all groups > dotnet interop > august 2007 >
You're in the

dotnet interop

group:

Cannot call simple WinApi function


Cannot call simple WinApi function Carl
8/15/2007 1:50:55 PM
dotnet interop:
Hi,

I've got stuck on calling the following WinApi function. I've tried lots of
different datatypes and read alot about which to use in the documentations,
but everything fails. Does anyone know how to do it?

The Call:

StringBuilder sb = new StringBuilder(255);
IntPtr handle = new IntPtr();
uint result = GetModuleFileName(handle, out sb, (uint)255);

I want to send "null" as the handle, to get the currently running process
path.

My import declaration:
[DllImport("Kernel32.dll")]
public static extern uint GetModuleFileName(IntPtr Handle, out StringBuilder
Filename, uint Size);

The MSDN documentation of the Api:

DWORD WINAPI GetModuleFileName(
HMODULE hModule,
LPTSTR lpFilename,
DWORD nSize
);

I hope someone can assist me with this!

regards

Carl

Re: Cannot call simple WinApi function Carl
8/15/2007 2:15:14 PM
[quoted text, click to view]

Never mind, I got it to work by removing the "out" keyword!

Re: Cannot call simple WinApi function wawang NO[at]SPAM online.microsoft.com (
8/16/2007 2:18:43 AM
Hi Carl,

FYI: you may find following document useful when using P/Invoke to call
win32 dlls:

#.NET: Calling Win32 DLLs in C# with P/Invoke -- MSDN Magazine, July 2003
http://msdn.microsoft.com/msdnmag/issues/03/07/NET/



Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
AddThis Social Bookmark Button