P/Invoke calling mismatch

G

Guest

Can someone suggest a way to get the functions to match - I am trying to get
file versions, etc info. But its still in unmanaged code as far as I can
find.
VGetFileVersionInfoSizeA' has unbalanced the stack. This is likely because
the managed PInvoke signature does not match the unmanaged target signature.
And should I be using by ref or out for those return values ?? Thanks

public class APICall
{// Private Declare Function GetFileVersionInfoSize Lib "version.dll" Alias
"GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As
Long) As Long
//Private Declare Function GetFileVersionInfo Lib "version.dll" Alias
"GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As
Long, ByVal dwLen As Long, lpData As Any) As Long

[DllImport("version.dll")]
public static extern long GetFileVersionInfoSizeA(string
lptstrFilename, long lpdwHandle);
[DllImport("version.dll")]
public static extern long GetFileVersionInfoA(string
lptstrFilename, long lpdwHandle, long dwLen, string lpData);

public string extVersionGetFileVersionInfo(string fullFileName)
{
string theVersion = "";
string lpData = "";
long hWnd=0;
try
{ // crash on first API call
long dwLen = GetFileVersionInfoSizeA(fullFileName,
hWnd);
long val = GetFileVersionInfoA(fullFileName, 0, dwLen,
lpData);

}
catch (Exception e)
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

I cannot find GetFileVersionInfoSizeA in the API, where it came from?
 
W

Willy Denoyette [MVP]

Change all your long's into int's, long in .NET is 64 bit.

Willy.



| Can someone suggest a way to get the functions to match - I am trying to
get
| file versions, etc info. But its still in unmanaged code as far as I can
| find.
| VGetFileVersionInfoSizeA' has unbalanced the stack. This is likely because
| the managed PInvoke signature does not match the unmanaged target
signature.
| And should I be using by ref or out for those return values ?? Thanks
|
| public class APICall
| {// Private Declare Function GetFileVersionInfoSize Lib "version.dll"
Alias
| "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As
| Long) As Long
| //Private Declare Function GetFileVersionInfo Lib "version.dll" Alias
| "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As
| Long, ByVal dwLen As Long, lpData As Any) As Long
|
| [DllImport("version.dll")]
| public static extern long GetFileVersionInfoSizeA(string
| lptstrFilename, long lpdwHandle);
| [DllImport("version.dll")]
| public static extern long GetFileVersionInfoA(string
| lptstrFilename, long lpdwHandle, long dwLen, string lpData);
|
| public string extVersionGetFileVersionInfo(string fullFileName)
| {
| string theVersion = "";
| string lpData = "";
| long hWnd=0;
| try
| { // crash on first API call
| long dwLen = GetFileVersionInfoSizeA(fullFileName,
| hWnd);
| long val = GetFileVersionInfoA(fullFileName, 0, dwLen,
| lpData);
|
| }
| catch (Exception e)
|
|
|
|
|
| --
| Andrew
 
M

Mattias Sjögren

Can someone suggest a way to get the functions to match - I am trying to get
file versions, etc info. But its still in unmanaged code as far as I can
find.

Have you tried using the FileVersionInfo class?

VGetFileVersionInfoSizeA' has unbalanced the stack. This is likely because
the managed PInvoke signature does not match the unmanaged target signature.

Exactly as what the message says. All your longs should be (u)ints.
www.pinvoke.net is a good place to check for P/Invoke method
signatures.

And should I be using by ref or out for those return values ??

out IntPtr for the output handle. The version info buffer is best
represented as a byte[].


Mattias
 
G

Guest

Yes ! Thanks I thought there was a class for that , but I could not find it
by Google or by MSDN - my criteria were just off and it was not under
System.IO. where I thought it would be. THANKS.... to all also for all the
tips about P/INVOKE.

this however is exactly what I need and managed :
System.Diagnostics.FileVersionInfo finfo =
FileVersionInfo.GetVersionInfo(fullFilePath);


--
Andrew


Mattias Sjögren said:
Can someone suggest a way to get the functions to match - I am trying to get
file versions, etc info. But its still in unmanaged code as far as I can
find.

Have you tried using the FileVersionInfo class?

VGetFileVersionInfoSizeA' has unbalanced the stack. This is likely because
the managed PInvoke signature does not match the unmanaged target signature.

Exactly as what the message says. All your longs should be (u)ints.
www.pinvoke.net is a good place to check for P/Invoke method
signatures.

And should I be using by ref or out for those return values ??

out IntPtr for the output handle. The version info buffer is best
represented as a byte[].


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top