GetProcAddress

GetProcAddress

Hello,
I have a quick question regarding the GetProcAddress command in Compaq Visual Fortran. In all the examples of using GetProcAddress that I have found so far, the name of the procedure is known in advance and hard coded. For example:

q = getprocaddress(p, "SUB1"C)

I have to repeat this command a number of times with variations on the null terminated string (SUB1,SUB2,SUB3 etc.) and am having no luck constructing the null terminated string and then using it... here is a code snippet

...
INTEGER:: j
CHARACTER*12:: jStr
CHARACTER*7:: SubNum
INTEGER(INT_PTR_KIND()) paa(100)
POINTER (p,i)

DO j=1,100
!write the integer variable j to the string variable jStr
WRITE(jStr,*) j
!change the leading blanks to trailing blanks
jStr=ADJUSTL(jStr)
!concatenate jStr onto SUB
SubNum="SUB"//TRIM(jStr)
paa(j) = GetProcAddress(p,SubNum)
END DO
...

GetProcAddress always returns NUL and I suspect that it is because the argument SubNum is not really a null terminated string.

if I replace the line
paa(j) = GetProcAddress(p,SubNum)
with
paa(1) = GetProcAddress(p,"SUB1"C)

I get the proper pointer but would have to type in 100 such lines instead of using the DO loop. Any hints as to what I am doing wrong here would be much appreciated.

Cheers,
David

publicaciones de 2 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

You need to null terminate the string, in your case:

paa(j) = GetProcAddress(p,TRIM(SubNum)//CHAR(0))

James

Inicie sesión para dejar un comentario.