Import API functions from DLL

HI!

I need to import the following functions from User32.dll libray

1) OpenWindowStation
In MSDN it is described with argument and return value:

HWINSTA WINAPI OpenWindowsStation(LPTSTR lpszWinSta, BOOL fInherit, ACCESS_MASK dwDesiredAccess)

2)GetThreadDesktop
MSDN description:

HDESK WINAPI GetThreadDesktop(DWORD dwThreadId)

3) GetUserObjectInformation
MSDN description:

BOOL WINAPI GetUserObjectInformation(HANDLE hObj, int nIndex, PVOID pvInfo, DWORD nLength, LPDWORD lpnLengthNeeded)

I know that dll function import is made like that:

[DllImport("User32.dll", ExactSpelling=true)]
public static extern IntPtr GetThreadDesktop(int dwThreadId);

I. The first problem is how to change variables types for types understood by C# compiler.

II.The second problem - I tried to import API functions from DLL in a service code, but it gave no effect - when the service goes to the part of the code containing imported function it doesn't execute it. While in an application everithing goes fine.

I'll be grateful for any hints...



Answer this question

Import API functions from DLL