473,385 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

P/Invoke calling mismatch

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
Jun 26 '06 #1
4 5503
Hi,

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

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"andrewcw" <an******@acw.com> wrote in message
news:01**********************************@microsof t.com...
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

Jun 26 '06 #2
Change all your long's into int's, long in .NET is 64 bit.

Willy.

"andrewcw" <an******@acw.com> wrote in message
news:01**********************************@microsof t.com...
| 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
Jun 26 '06 #3
>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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 26 '06 #4
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" wrote:
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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jun 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Yoni Rabinovitch | last post by:
Is it possible to invoke a C# delegate/event handler asynchronously, from unmanaged C++ ? I assume this requires a Managed C++ wrapper, which would call BeginInvoke on the delegate ? Is this...
2
by: Tom | last post by:
Hi Everybod I want to update some controls in a form from another threads. I did it by passing the form to that thread and calling a delegate with Form1.Invoke, I want to have just one delegeate...
2
by: rawCoder | last post by:
Hi I am having this InvalidOperationException with message Cannot call Invoke or InvokeAsync on a control until the window handle has been created This is raised when i try to invoke a method...
1
by: webstuff | last post by:
Hi, I'm getting a 'Type mismatch' exception when calling the Word.Application.Documents.Open method when using the Office XP 2003 PIAs. the actual error is: ...
1
by: Thai Mai Shu | last post by:
What is wrong with my call below. If I change the delegate and the CallBackComplete function to not take in parameters then the .Invoke call works fine. As soon as I put the parameters back I...
2
by: andrewbb | last post by:
This is fairly simple code, what am I missing or is there a potential workaround? It fails when passing someParms to Invoke with "Parameter count mismatch". I created a test with an empty form...
2
by: John Lutz | last post by:
Our app is mainly COM based. We allow .NET plug-ins. When a plug-in is installed, it receives a COM pointer to the app. The plug-in implements our IExtensionImpl interface and gets the app...
23
by: Thomas Due | last post by:
Hi, I have a class which monitors a TCP socket. This will on occasion raise an event which can be handled by a GUI. Now, I am aware of the if(InvokeRequire) { EventHandler d = new...
1
by: SAL | last post by:
Hello, I'm developing this remoting app (.net 2.0) and I need to bring the server app's form to the front often. Since you can not do cross-thread communication on a form or control without using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.