Error with CallFunction...

Just starting out? Need help? Post your questions and find answers here.
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Error with CallFunction...

Post by DevilDog »

Hey everyone,
I'm getting an error:
Bad paremeter type, number expected instead of a string
on this line of code:

Code: Select all

     dwLen = CallFunction(1,"GetFileVersionInfoSizeA",lptstrFilename$,@lpdwHandle) 
 
Problem is that I haven't changed that code at all. The only thing that has changed is that I upgraded to the lastest 4.40 Beta version 2. Also, the parameter types seem to match the function's tooltip help definition.

Anyone know what I might be able to check?

Thanks
Devildog
When all is said and done, more is said than done.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Code: Select all

dwLen = CallFunction(1,"GetFileVersionInfoSizeA",@lptstrFilename$,@lpdwHandle) 
I may look like a mule, but I'm not a complete ass.
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Post by DevilDog »

Srod,
Thanks for the help, now I'm getting
Bad parameter type: a string is expected
Any ideas?

Devildog
When all is said and done, more is said than done.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

My first post was incorrect and I since edited the post. Please check that you are using the following :

Code: Select all

dwLen = CallFunction(1,"GetFileVersionInfoSizeA",@lptstrFilename$,@lpdwHandle) 
I may look like a mule, but I'm not a complete ass.
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Post by DevilDog »

I tried that as well and I'm receiving the same thing:
Bad paremeter type, number expected instead of a string
When all is said and done, more is said than done.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Doesn't make sense.

Can you post the code?
I may look like a mule, but I'm not a complete ass.
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Post by DevilDog »

Sure, this is the whole procedure:

Code: Select all

Procedure.s GFVI_GetInfo(lptstrFilename$,lekFlags,bFieldName);- get exe/dll file information [gfvi] 
  ;CallDebugger
  Protected lpdwHandle.l, dwLen.w, lpData.l, lplpBuffer.l, puLen.l, *pBlock, lpSubBlock$ 
  Protected nSize.w, szLang$, bBit.b, lekFlag.l, sElement$, sGFVI$ 
  
  lplpBuffer = 0 : puLen = 0 : sGFVI$ = "" : nSize = 128 : szLang$ = Space(nSize) 
  
  If FileSize(lptstrFilename$)>0 
    If OpenLibrary(1,"Version.dll") 
      dwLen = CallFunction(1,"GetFileVersionInfoSizeA",@lptstrFilename$,@lpdwHandle) 
      If dwLen>0 
        *pBlock=AllocateMemory(dwLen) 
        If *pBlock>0 
          Result = CallFunction(1,"GetFileVersionInfoA",lptstrFilename$,0,dwLen,*pBlock) 
          If Result 
            lpSubBlock$ = "\\VarFileInfo\\Translation" 
            Result      = CallFunction(1,"VerQueryValueA",*pBlock,lpSubBlock$,@lplpBuffer,@puLen) 
            If Result 
              CPLI$  = RSet(Hex(PeekW(lplpBuffer)),4,"0")+RSet(Hex(PeekW(lplpBuffer+2)),4,"0") 
              Result = CallFunction(1,"VerLanguageNameA",PeekW(lplpBuffer),@szLang$,nSize) 
            EndIf 
            lekFlag = 1 
            For bBit = 1 To 12 
              If lekFlag & lekFlags 
                sElement$   = GFVI_GetElementName(lekFlag) 
                lpSubBlock$ = "\\StringFileInfo\\"+CPLI$+"\\"+sElement$ 
                Result      = CallFunction(1,"VerQueryValueA",*pBlock,lpSubBlock$,@lplpBuffer,@puLen) 
                If Result 
                  If sGFVI$<>"" : sGFVI$+Chr(10) : EndIf 
                  If bFieldName 
                    sGFVI$=sGFVI$+sElement$+":"+Chr(9)+PeekS(lplpBuffer) 
                  Else 
                    sGFVI$=sGFVI$+PeekS(lplpBuffer) 
                  EndIf 
                  
                EndIf 
              EndIf 
              lekFlag << 1 
            Next 
            If lekFlag & lekFlags 
              If sGFVI$<>"" : sGFVI$+Chr(10) : EndIf 
              If bFieldName 
                sElement$ = GFVI_GetElementName(lekFlag) 
                sGFVI$    = sGFVI$+sElement$+":"+Chr(9)+szLang$ 
              Else 
                sGFVI$    = sGFVI$+szLang$ 
              EndIf 
            EndIf 
          EndIf 
          FreeMemory(*pBlock) 
        EndIf 
      EndIf 
      CloseLibrary(1) 
    EndIf 
  EndIf 
  ProcedureReturn sGFVI$ 
EndProcedure 
When all is said and done, more is said than done.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

REMOVED.
Last edited by srod on Tue Sep 01, 2009 8:12 pm, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Post by DevilDog »

well like I said, it was working up until the beta. I'm going to revert back to the release version and see if that fixes it.
When all is said and done, more is said than done.
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Post by DevilDog »

Yeah, must be a bug because it works under 4.31. Where can I post this to alert the PB team?
When all is said and done, more is said than done.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I take back the confirmed part. The following runs fine.

Code: Select all

If OpenLibrary(0, "User32.dll")
  CallFunction(0, "MessageBoxA", 0, @"hi", @"hello", 0)
  CloseLibrary(0)
EndIf
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Hang on, you haven't adjusted all of your CallFunction()'s correctly!

Try the following :

Code: Select all

Procedure.s GFVI_GetInfo(lptstrFilename$,lekFlags,bFieldName);- get exe/dll file information [gfvi] 
  ;CallDebugger 
  Protected lpdwHandle.l, dwLen.w, lpData.l, lplpBuffer.l, puLen.l, *pBlock, lpSubBlock$ 
  Protected nSize.w, szLang$, bBit.b, lekFlag.l, sElement$, sGFVI$ 
  
  lplpBuffer = 0 : puLen = 0 : sGFVI$ = "" : nSize = 128 : szLang$ = Space(nSize) 
  
  If FileSize(lptstrFilename$)>0 
    If OpenLibrary(1,"Version.dll") 
      dwLen = CallFunction(1,"GetFileVersionInfoSizeA",@lptstrFilename$,@lpdwHandle) 
      If dwLen>0 
        *pBlock=AllocateMemory(dwLen) 
        If *pBlock>0 
          Result = CallFunction(1,"GetFileVersionInfoA",@lptstrFilename$,0,dwLen,*pBlock) 
          If Result 
            lpSubBlock$ = "\\VarFileInfo\\Translation" 
            Result      = CallFunction(1,"VerQueryValueA",*pBlock,@lpSubBlock$,@lplpBuffer,@puLen) 
            If Result 
              CPLI$  = RSet(Hex(PeekW(lplpBuffer)),4,"0")+RSet(Hex(PeekW(lplpBuffer+2)),4,"0") 
              Result = CallFunction(1,"VerLanguageNameA",PeekW(lplpBuffer),@szLang$,nSize) 
            EndIf 
            lekFlag = 1 
            For bBit = 1 To 12 
              If lekFlag & lekFlags 
                sElement$   = GFVI_GetElementName(lekFlag) 
                lpSubBlock$ = "\\StringFileInfo\\"+CPLI$+"\\"+sElement$ 
                Result      = CallFunction(1,"VerQueryValueA",*pBlock,@lpSubBlock$,@lplpBuffer,@puLen) 
                If Result 
                  If sGFVI$<>"" : sGFVI$+Chr(10) : EndIf 
                  If bFieldName 
                    sGFVI$=sGFVI$+sElement$+":"+Chr(9)+PeekS(lplpBuffer) 
                  Else 
                    sGFVI$=sGFVI$+PeekS(lplpBuffer) 
                  EndIf 
                  
                EndIf 
              EndIf 
              lekFlag << 1 
            Next 
            If lekFlag & lekFlags 
              If sGFVI$<>"" : sGFVI$+Chr(10) : EndIf 
              If bFieldName 
                sElement$ = GFVI_GetElementName(lekFlag) 
                sGFVI$    = sGFVI$+sElement$+":"+Chr(9)+szLang$ 
              Else 
                sGFVI$    = sGFVI$+szLang$ 
              EndIf 
            EndIf 
          EndIf 
          FreeMemory(*pBlock) 
        EndIf 
      EndIf 
      CloseLibrary(1) 
    EndIf 
  EndIf 
  ProcedureReturn sGFVI$ 
EndProcedure  

I may look like a mule, but I'm not a complete ass.
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Post by DevilDog »

OK, the code you posted compiles fine under 4.40 beta 2 with the changes you made.

What's changed? why did the old code work under 4.31 and not under the beta?
When all is said and done, more is said than done.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

When using a literal string such as "test", the compiler will now treat this as a string and will not automatically substitute the address of the underlying character array in situations in which the function prototype specifies an integer etc. Hence for api functions you need to use the "address of" operator @ etc.

By the way, since you are calling the same function(s) more than once you would be far better using CallFunctionFast(). Better still use prototypes. Even better, import the functions directly from the import library "Version.lib".
I may look like a mule, but I'm not a complete ass.
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Post by DevilDog »

Thanks for the explanation, it's great info.

And I'll look into your suggestions as well.
When all is said and done, more is said than done.
Post Reply