DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 15 Aug 2007 13:50:55 +0200,    posted on: microsoft.public.dotnet.framework.interop        back       

Thread Index
  1    Carl am
          2    Carl am
                 3    (Walter Wang [MSFT])


Cannot call simple WinApi function   
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
Date:Wed, 15 Aug 2007 13:50:55 +0200   Author:  

Re: Cannot call simple WinApi function   

> 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
> );


Never  mind, I got it to work by removing the "out" keyword!
Date:Wed, 15 Aug 2007 14:15:14 +0200   Author:  

Re: Cannot call simple WinApi function   
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.
Date:Thu, 16 Aug 2007 02:18:43 GMT   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us