Click here to Skip to main content
Click here to Skip to main content

Win32 API: C++ to .NET

By , 8 Mar 2005
 

Introduction

I am writing an article to give a reference to developers who need to use API imports in their .NET programs to call C++ functions. I haven't found a single site that looks good or is totally complete with all the data types or has them converted correctly. So, I decided to write one. I also recommend using any new .NET function that does the same thing as an API if it is available. At least 75% of the API has already been converted to .NET and is available in various classes. This is because they usually work better and look nicer. If you have any questions send me an email or post them to the message board.

.NET API declaration form

VB.NET

Declare Function <Name> Lib <dll name> <Optional fields> (<params>) _
                                                      As <return type>

C# definition

[DllImport("<dll name>", <optional fields>)] 
        static extern <return type> <Method name> (<Params>)

Managed C++ .NET

[DllImport("<Dll name>",<optional fields>)]
     static <return type> <Function name>( <Params>);

Examples

Windows API reference for C#, VB.NET & VB6 - This site has every major API declaration for VB.NET, C#.NET and some VB6.

Here is a program I have made that uses these sites:

VB.NET

Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA"(_
           ByVal dwFlags As Integer, ByRef lpSource As Object, _
           ByVal dwMessageId As Integer, ByVal dwLanguageId As Integer, _
           ByVal lpBuffer As String, ByVal nSize As Integer, _
           ByRef Arguments As Integer) As Integer

C# definition

[DllImport("kernel32.dll", SetLastError=true)] 
   static extern int FormatMessageA ( int dwFlags, ref object lpSource, 
   int dwMessageId, int dwLanguageId, string lpBuffer, 
   int nSize, ref int Arguments)

Managed C++. NET

[DllImport("KERNEL32.DLL",EntryPoint="MoveFileW",
   SetLastError=true,CharSet=CharSet::Unicode,ExactSpelling=true,
   CallingConvention=CallingConvention::StdCall)]
   static bool MoveFile( String^ src, String^ dst );

Tips

  1. In this list, a pointer to a data type is represented like P, for example DWORD* = PDWORD.
  2. Some types like UIntPtr are not CLS compliant so I use IntPtr instead, but you can use any of these.
  3. The first choice that comes up after the "=" in the IDE’s Intellisense is the best choice usually.
  4. When using strings in COM Interop, for inputs you always use string for WCHAR*, TCHAR*, etc. For outputs you can use string or StringBuilder, but sometimes you need to use an IntPtr and marshal the characters out of it using Marshal.PtrToStructure() and increment the pointer till you get null characters. To increment a pointer turn it into an int and increase the size each time by the size of the type you get from Marshal.PtrToStructure() each time. E.g. : pointer += Marshal.SizeOf(<last object you got back>);
  5. Sometimes certain data types that aren't correct will work. E.g.: An int could be used for a uint.
  6. If you need to convert an IntPtr back to an int or some other class, use Marshal.PtrToStructure() or some other IntPtr method.
  7. If the API your using is dependent on ANSI or Unicode, make sure you select the correct one so that your strings will be formatted correctly. Look at the CharSet enumeration.
  8. Most of the API calls can be written in a managed declaration, but some need pointers, in C# you can use pointers if you surround the code with the unsafe keyword and use the /unsafe compiler option.
  9. If you want to make sure that the garbage collector doesn't eat your IntPtr in an API call you can use a HandleRef type.
  10. When you need to declare structs for API, make sure they have the StructLayout.Sequential attribute. Also sometimes you may need to change the packing on a struct to make it work right, but usually you don't.
  11. When passing or retrieving arrays to/from API methods, look if it's a pointer to an array or a direct input array, if it's a pointer you need to marshal it to an IntPtr possibly.
  12. Sometimes choosing the type to use can be hard but you'll get the hang of it after a few times.
  13. When I show the types to use for pointers to data types I say IntPtr or the data type it points to, sometimes you can just say ref <datatype> or out <datatype>, but unless it's an input char * you need to use IntPr for inputs and ref IntPtr for outputs.
  14. If your function declaration fails to work don't always blame it on the way you wrote declaration, it may be a call to the previous methods that messed it up, or just a bad data getting passed in.
  15. Use the Marshal and MarshalAs classes only when you have to, as they take up more processing power in certain situations.

Data type conversion sheet : C++ to .NET

Term

Description

ATOM

.NET = ushort

C++ = typedef WORD ATOM;

BOOL

.NET = bool or int

C++ = typedef int BOOL;

BOOLEAN

.NET = bool or byte

C++ = typedef BYTE BOOLEAN;

BYTE

.NET = byte

C++ = typedef unsigned char BYTE;

CALLBACK

.NET = delegate

C++ = #define CALLBACK __stdcall

CHAR

.NET = char

C++ = typedef char CHAR;

COLORREF

.NET = uint

C++ = typedef DWORD COLORREF;

CONST

.NET = const

C++ = #define CONST const

DWORD

.NET = uint

C++ = typedef unsigned long DWORD;

DWORDLONG

ulong

C++ = typedef ULONGLONG DWORDLONG;

DWORD_PTR

DWORD *

.NET = uint or IntPtr

C++ = typedef ULONG_PTR DWORD_PTR;

DWORD32

.NET = uint

C++ = typedef unsigned int DWORD32;

DWORD64

.NET = ulong

C++ = typedef unsigned __int64 DWORD64;

FLOAT

.NET = single

C++ = typedef float FLOAT;

HACCEL

.NET = IntPtr

C++ = typedef HANDLE HACCEL;

HANDLE

.NET = IntPtr

C++ = typedef PVOID HANDLE;

HBITMAP

.NET = IntPtr

C++ = typedef HANDLE HBITMAP;

HBRUSH

.NET = IntPtr

C++ = typedef HANDLE HBRUSH;

HCOLORSPACE

.NET = IntPtr

C++ = if(WINVER >= 0x0400)

C++ = typedef HANDLE HCOLORSPACE;

HCONV

.NET = IntPtr

C++ = typedef HANDLE HCONV;

HCONVLIST

.NET = IntPtr

C++ = typedef HANDLE HCONVLIST;

HCURSOR

.NET = IntPtr

C++ = typedef HICON HCURSOR;

HDC

.NET = IntPtr

C++ = typedef HANDLE HDC;

HDDEDATA

.NET = IntPtr

C++ = typedef HANDLE HDDEDATA;

HDESK

.NET = IntPtr

C++ = typedef HANDLE HDESK;

HDROP

.NET = IntPtr

C++ = typedef HANDLE HDROP;

HDWP

.NET = IntPtr

C++ = typedef HANDLE HDWP;

HENHMETAFILE

.NET = IntPtr

C++ = typedef HANDLE HENHMETAFILE;

HFILE

.NET = int

C++ = typedef int HFILE;

HFONT

.NET = IntPtr

C++ = typedef HANDLE HFONT;

HGDIOBJ

.NET = IntPtr

C++ = typedef HANDLE HGDIOBJ;

HGLOBAL

.NET = IntPtr

C++ = typedef HANDLE HGLOBAL;

HHOOK

.NET = IntPtr

C++ = typedef HANDLE HHOOK;

HICON

.NET = IntPtr

C++ = typedef HANDLE HICON;

HINSTANCE

.NET = IntPtr

C++ = typedef HANDLE HINSTANCE;

HKEY

.NET = IntPtr

C++ = typedef HANDLE HKEY;

HKL

.NET = IntPtr

C++ = typedef HANDLE HKL;

HLOCAL

.NET = IntPtr

C++ = typedef HANDLE HLOCAL;

HMENU

.NET = IntPtr

C++ = typedef HANDLE HMENU;

HMETAFILE

.NET = IntPtr

C++ = typedef HANDLE HMETAFILE;

HMODULE

.NET = IntPtr

C++ = typedef HINSTANCE HMODULE;

HMONITOR

.NET = IntPtr

if(WINVER >= 0x0500)

C++ = typedef HANDLE HMONITOR;

HPALETTE

.NET = IntPtr

C++ = typedef HANDLE HPALETTE;

HPEN

.NET = IntPtr

C++ = typedef HANDLE HPEN;

HRESULT

.NET = int or uint

C++ = typedef LONG HRESULT;

HRGN

.NET = IntPtr

C++ = typedef HANDLE HRGN;

HRSRC

.NET = IntPtr

C++ = typedef HANDLE HRSRC;

HSZ

.NET = IntPtr

C++ = typedef HANDLE HSZ;

HWINSTA

.NET = IntPtr

C++ = typedef HANDLE WINSTA;

HWND

.NET = IntPtr

C++ = typedef HANDLE HWND;

INT

.NET = int

C++ = typedef int INT;

INT_PTR

.NET = IntPtr

#if defined(_WIN64)

C++ = typedef __int64 INT_PTR;

#else

C++ = typedef int INT_PTR;

INT32

.NET = int

C++ = typedef signed int INT32;

INT64

.NET = long

C++ = typedef signed __int64 INT64;

LANGID

.NET = ushort or int

C++ = typedef WORD LANGID;

LCID

.NET = uint

C++ = typedef DWORD LCID;

LCTYPE

.NET = uint

C++ = typedef DWORD LCTYPE;

LGRPID

.NET = uint

C++ = typedef DWORD LGRPID;

LONG

.NET = int

C++ = typedef long LONG;

LONGLONG

.NET = long

#if !defined(_M_IX86)

C++ = typedef __int64 LONGLONG;

#else

C++ = typedef double LONGLONG;

LONG_PTR

.NET = IntPtr

#if defined(_WIN64)

C++ = typedef __int64 LONG_PTR;

#else

C++ = typedef long LONG_PTR;

LONG32

.NET = int

C++ = typedef signed int LONG32;

LONG64

.NET = long

C++ = typedef __int64 LONG64;

LPARAM

.NET = IntPtr

C++ = typedef LONG_PTR LPARAM;

LPBOOL

Bool *

.NET = IntPtr or bool

C++ = typedef BOOL *LPBOOL;

LPBYTE

Byte *

.NET = IntPtr or byte

C++ = typedef BYTE *LPBYTE;

LPCOLORREF

.NET = IntPtr or uint

C++ = typedef DWORD *LPCOLORREF;

LPCSTR

.NET = string or IntPtr or StringBuilder

C++ = typedef CONST CHAR *LPCSTR;

LPCTSTR

.NET = string or IntPtr or StringBuilder

#ifdef UNICODE

C++ = typedef LPCWSTR LPCTSTR;

#else

C++ = typedef LPCSTR LPCTSTR;

LPCVOID

.NET = IntPtr

C++ = typedef CONST void *LPCVOID;

LPCWSTR

.NET = string or IntPtr or StringBuilder

C++ = typedef CONST WCHAR *LPCWSTR;

LPDWORD

.NET = IntPtr or uint

C++ = typedef DWORD *LPDWORD;

LPHANDLE

.NET = IntPtr

C++ = typedef HANDLE *LPHANDLE;

LPINT

.NET = IntPtr or int

C++ = typedef int *LPINT;

LPLONG

.NET = IntPtr or int

C++ = typedef long *LPLONG;

LPSTR

.NET = string or IntPtr or StringBuilder

C++ = typedef CHAR *LPSTR;

LPTSTR

.NET = string or IntPtr or StringBuilder

#ifdef UNICODE

C++ = typedef LPWSTR LPTSTR;

#else

C++ = typedef LPSTR LPTSTR;

LPVOID

.NET = IntPtr

C++ = typedef void *LPVOID;

LPWORD

.NET = IntPtr or ushort

C++ = typedef WORD *LPWORD;

LPWSTR

.NET = string or IntPtr or StringBuilder

C++ = typedef WCHAR *LPWSTR;

LRESULT

.NET = IntPtr or int

C++ = typedef LONG_PTR LRESULT;

PBOOL

.NET = IntPtr or bool

C++ = typedef BOOL *PBOOL;

PBOOLEAN

.NET = IntPtr or bool

C++ = typedef BOOLEAN *PBOOLEAN;

PBYTE

.NET = IntPtr or byte

C++ = typedef BYTE *PBYTE;

PCHAR

.NET = IntPtr or char

C++ = typedef CHAR *PCHAR;

PCSTR

.NET = string or IntPtr or StringBuilder

C++ = typedef CONST CHAR *PCSTR;

PCTSTR

.NET = string or IntPtr or StringBuilder

#ifdef UNICODE

C++ = typedef LPCWSTR PCTSTR;

#else

C++ = typedef LPCSTR PCTSTR;

PCWSTR

.NET = string or IntPtr or StringBuilder

C++ = typedef CONST WCHAR *PCWSTR;

PDWORD

.NET = IntPtr or uint

C++ = typedef DWORD *PDWORD;

PDWORDLONG

.NET = IntPtr or ulong

C++ = typedef DWORDLONG *PDWORDLONG;

PDWORD_PTR

.NET = IntPtr or uint

C++ = typedef DWORD_PTR *PDWORD_PTR;

PDWORD32

.NET = IntPtr or uint

C++ = typedef DWORD32 *PDWORD32;

PDWORD64

.NET = IntPtr or ulong

C++ = typedef DWORD64 *PDWORD64;

PFLOAT

.NET = IntPtr or single

C++ = typedef FLOAT *PFLOAT;

PHANDLE

.NET = IntPtr

C++ = typedef HANDLE *PHANDLE;

PHKEY

.NET = IntPtr

C++ = typedef HKEY *PHKEY;

PINT

.NET = IntPtr or int

C++ = typedef int *PINT;

PINT_PTR

.NET = IntPtr

C++ = typedef INT_PTR *PINT_PTR;

PINT32

.NET = IntPtr or int

C++ = typedef INT32 *PINT32;

PINT64

.NET = IntPtr or long

C++ = typedef INT64 *PINT64;

PLCID

.NET = IntPtr or uint

C++ = typedef PDWORD PLCID;

PLONG

.NET = IntPtr or int

C++ = typedef LONG *PLONG;

PLONGLONG

.NET = IntPtr or long

C++ = typedef LONGLONG *PLONGLONG;

PLONG_PTR

.NET = IntPtr or int

C++ = typedef LONG_PTR *PLONG_PTR;

PLONG32

.NET = IntPtr or int

C++ = typedef LONG32 *PLONG32;

PLONG64

.NET = IntPtr or long

C++ = typedef LONG64 *PLONG64;

POINTER_32

.NET = IntPtr or int

#if defined(_WIN64)

#define POINTER_32 __ptr32

#else

#define POINTER32

POINTER_64

.NET = IntPtr or long

#define POINTER_64 __ptr64

PSHORT

.NET = IntPtr or short

C++ = typedef SHORT *PSHORT;

PSIZE_T

.NET = IntPtr

C++ = typedef SIZE_T *PSIZE_T;

PSSIZE_T

.NET = IntPtr

C++ = typedef SSIZE_T *PSSIZE_T;

PSTR

.NET = IntPtr or string or StringBuilder

C++ = typedef CHAR *PSTR;

PTBYTE

.NET = IntPtr or char

C++ = typedef TBYTE *PTBYTE;

PTCHAR

.NET = IntPtr or string or StringBuilder

C++ = typedef TCHAR *PTCHAR;

PTSTR

.NET = IntPtr or string or StringBuilder

#ifdef UNICODE

C++ = typedef LPWSTR PTSTR;

#else

C++ = typedef LPSTR PTSTR;

PUCHAR

.NET = IntPtr or string or StringBuilder

C++ = typedef UCHAR *PUCHAR;

PUINT

.NET = IntPtr or uint

C++ = typedef UINT *PUINT;

PUINT_PTR

.NET = IntPtr or uint

C++ = typedef UINT_PTR *PUINT_PTR;

PUINT32

.NET = IntPtr or uint

C++ = typedef UINT32 *PUINT32;

PUINT64

.NET = IntPtr or ulong

C++ = typedef UINT64 *PUINT64;

PULONG

.NET = IntPtr or uint

C++ = typedef ULONG *PULONG;

PULONGLONG

.NET = IntPtr or ulong

C++ = typedef ULONGLONG *PULONGLONG;

PULONG_PTR

.NET = IntPtr or uint:

C++ = typedef ULONG_PTR *PULONG_PTR;

PULONG32

.NET = IntPtr or uint

C++ = typedef ULONG32 *PULONG32;

PULONG64

.NET = IntPtr or ulong

C++ = typedef ULONG64 *PULONG64;

PUSHORT

.NET = IntPtr or ushort

C++ = typedef USHORT *PUSHORT;

PVOID

.NET = IntPtr

C++ = typedef void *PVOID;

PWCHAR

.NET = IntPtr or string:

C++ = typedef WCHAR *PWCHAR;

PWORD

.NET = IntPtr or ushort

C++ = typedef WORD *PWORD;

PWSTR

.NET = IntPtr or string or StringBuilder

C++ = typedef WCHAR *PWSTR;

SC_HANDLE

.NET = IntPtr

C++ = typedef HANDLE SC_HANDLE;

SC_LOCK

.NET = IntPtr

C++ = typedef LPVOID SC_LOCK;

SERVICE_STATUS_HANDLE

.NET = IntPtr

C++ = typedef HANDLE SERVICE_STATUS_HANDLE;

SHORT

.NET = short

C++ = typedef short SHORT;

SIZE_T

.NET = uint or IntPtr

C++ = typedef ULONG_PTR SIZE_T;

SSIZE_T

.NET = int or IntPtr

C++ = typedef LONG_PTR SSIZE_T;

TBYTE

.NET = char

#ifdef UNICODE

C++ = typedef WCHAR TBYTE;

#else

C++ = typedef unsigned char TBYTE;

TCHAR

.NET = char

#ifdef UNICODE

C++ = typedef WCHAR TCHAR;

#else

C++ = typedef char TCHAR;

UCHAR

.NET = char

C++ = typedef unsigned char UCHAR;

UINT

.NET = uint:

C++ = typedef unsigned int UINT;

UINT_PTR

.NET = UIntPtr or uint:

#if defined(_WIN64)

C++ = typedef unsigned __int64 UINT_PTR;

#else

C++ = typedef unsigned int UINT_PTR;

UINT32

.NET = uint

C++ = typedef unsigned int

UINT32;

UINT64

.NET = ulong

C++ = typedef usigned __int

64 UINT64;

ULONG

.NET = uint:

C++ = typedef unsigned long ULONG;

ULONGLONG

.NET = ulong:

#if !defined(_M_IX86)

C++ = typedef unsigned __int64 ULONGLONG;

#else

C++ = typedef double ULONGLONG

ULONG_PTR

.NET = IntPtr or uint

#if defined(_WIN64)

C++ = typedef unsigned __int64 ULONG_PTR;

#else

C++ = typedef unsigned long ULONG_PTR;

ULONG32

.NET = uint

C++ = typedef unsigned int ULONG32;

ULONG64

.NET = ulong

C++ = typedef unsigned __int64 ULONG64;

USHORT

.NET = ushort

C++ = typedef unsigned short USHORT;

USN

.NET = long

C++ = typedef LONGLONG USN;

VOID

.NET = void:

#define VOID void

WCHAR

.NET = char

C++ = typedef wchar_t WCHAR;

WINAPI

.NET = standard is default, look at the CallingConvention enumeration:

#define WINAPI __stdcall

WORD

.NET = ushort

C++ = typedef unsigned short WORD;

WPARAM

.NET = IntPtr or uint:

C++ = typedef UINT_PTR WPARAM;

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

kbrryder
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberwinxpdll14 Sep '11 - 4:33 
Thanks!
Question80 bit floating point data type (long double)membershazzard26 Aug '11 - 1:45 
Great work !
 
I do have a question though I'm hoping you can help me with.
I have a DLL written in Borland C++ which uses 'long double' data type (10 byte IEEE 754 standard floating point type), for which there seems to be absolutley no support for Frown | :(
So the C++ function is:
 
extern "C" dll_flag __stdcall long double      GetElectrodeResistivity(teLine line, teResistivityUnits Units)
 
I'm thinking I need to receive this as a pointer or a char array or something, then unpick it and use the data to create a 64 bit type that C# can deal with.
 
My first problem is : how do I receive a pointer (or even an array).
 
My first guess was to try and receive a char array like this:
[DllImport("SensorPhysics.dll")]
public static extern char[] GetElectrodeResistivity(teLine line, teResistivityUnits Units);
 
My second was to use an IntPtr, but that didn't seem to work either.
[DllImport("SensorPhysics.dll")]
public static extern IntPtr GetElectrodeResistivity(teLine line, teResistivityUnits Units);
 
..then
 
IntPtr xptr = physics_dll_import_funcs.GetCrossoverResistance(teLine.E_X_LINE);
 
char[] x_crossover_resistance = new char[10];
Marshal.Copy(xptr, x_crossover_resistance, 0, 10);
 
But that seems not to work either.
 
Any help would be appreciated Smile | :) Thanks.
GeneralMarshal.GetDelegateForFunctionPointer alternate in C# Compact FrameworkmemberSatyam Kumar10 Jun '10 - 16:26 
I am accessing a custom DLL in wince environment. For this i am using Function Pointers through C# using IntPtr. For the desktop we are having the function that is Marshal.GetDelegateForFunctionPointer. I don't have this functionality in the compact framework. Is there any alternate way to achieve this, please help me. Is there a way to get a delegate from IntPtr like we have it in the desktop version.
 
Desktop
MyCallBackHandler ManagedCallBack =
(MyCallBackHandler)Marshal.GetDelegateForFunctionPointer((IntPtr)Context, typeof(MyCallBackHandler));
 
Is there a alternate way in the .net compact framework as well ?
Make your self a void pointer so that you can type cast it every data type.

Generalplase Help Vc++DLL with VB.netmemberyang sung yeol2 Jan '10 - 18:19 
Vc DLL
-=========================================================
 
#ifndef IZZIXFELAPI32_H
#define IZZIXFELAPI32_H
 
#ifdef IZZIXFELAPI32_EXPORTS
#define IZZIXFELAPI32_API __declspec(dllexport)
#else
#define IZZIXFELAPI32_API __declspec(dllimport)
#endif
 
#define MAX_FEATUREVECT_LEN 480
#define HIGH_LEVEL 2
#define MEDIUM_LEVEL 1
#define LOW_LEVEL 0
 
// Error code of FingerAPI
#define FPAPIERR_NO 0
#define FPAPIERR_OK 1
#define FPAPIERR_GENERAL_ERROR -1
#define FPAPIERR_CAN_NOT_OPEN_DEVICE -2
 
#define FPAPIERR_MATCH_FAILED -101
#define FPAPIERR_CAN_NOT_ALLOC_MEMORY -201
#define FPAPIERR_VECT_FAILED -301
#define FPAPIERR_INVALID_IMAGESIZE -401
#define FPAPIERR_FAKER_FINGERPRINT -501
 
#define FPAPIERR_LEFT_FINGERPRINT -601
#define FPAPIERR_RIGHT_FINGERPRINT -602
#define FPAPIERR_UP_FINGERPRINT -603
#define FPAPIERR_DOWN_FINGERPRINT -604
#define FPAPIERR_SMALL_FINGERPRINT -605
 
#define FPAPIERR_TOO_WET -701
#define FPAPIERR_TOO_DRY -702
 

typedef struct
{
BYTE Data[MAX_FEATUREVECT_LEN];
} MINUTIAVECT, *LPMINUTIAVECT;
 

#ifdef __cplusplus
#define EXTWRN_C extern "C"
#else
#define EXTWRN_C
#endif
 
#ifdef __cplusplus
extern "C" {
#endif
 

namespace IzzixFELAPI32
{
void __stdcall DESEncode0(UCHAR *src,UCHAR *dec,UCHAR *key,int num);
void __stdcall DESEncode1(UCHAR *src,UCHAR *dec,UCHAR *key);
int __stdcall DESDecode(UCHAR *src,UCHAR *dec,UCHAR *key);
int __stdcall GetFinger(INT DeviceNumber,BYTE* pRawImage,LPMINUTIAVECT pFeature);
int __stdcall MatchFingerOneToOne(LPMINUTIAVECT pFeatureVect1,
LPMINUTIAVECT pFeatureVect2,
int securitylevel
);
 
int __stdcall MatchFingerOneToN(
LPMINUTIAVECT pFeatureVect,
LPMINUTIAVECT pDataBaseVects,
int nDataBaseSize,
int securitylevel,
int* pDataBaseIDs,
int* pAlwaysNULL
);
 
int __stdcall CollectFeature(LPMINUTIAVECT pFeatureVect1,
LPMINUTIAVECT pFeatureVect2,
LPMINUTIAVECT pFeatureVect3,
LPMINUTIAVECT pCollectVect
);
 
int __stdcall DisplayImage(HWND hWnd,int x1,int y1,int x2,int y2,
BYTE* pImage,int nWidth,int nHeight);
 
int __stdcall IsAvailableDevice(INT DeviceNumber);
int __stdcall GetSortedIndex(LPMINUTIAVECT pFeatureVect,
LPMINUTIAVECT pDataBaseVects,
int nDataBaseSize,
int* pIndex
);
 
int __stdcall GetFingerAPIVersion(UCHAR *Version);
int __stdcall GetSerial(INT DeviceNumber,UCHAR *Serial);
int __stdcall ConvertToISO(LPMINUTIAVECT pFeature,int fPos,unsigned char* Template);
int __stdcall ConvertFromISO(unsigned char* Template,LPMINUTIAVECT pFeature);
int __stdcall GetTouchStatus(INT DeviceNumber, BOOL &bTouch);
int __stdcall GetDevInfos(INT DeviceNumber, int *nProductType, int *nSensorType);
}
 
#ifdef __cplusplus
}
#endif
#endif
-=-=============================================================================================
my source is..
 
Declare Function IsAvailableDevice Lib "IzzixFELAPI32.dll" Alias "IsAvailableDevice" _
(ByVal DeviceNumber As Long) As Long
 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim RtnData As String = ""
Debug.WriteLine(GetSerial(0, RtnData))
end sub
 
but Error.. Error is ...
-> AccessViolationException
-> Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
GeneralThanks!memberdi~v~inci21 Dec '09 - 1:54 
great work x
Questionhelpmemberalmohandis3 Aug '08 - 9:50 
hi
i need to know how to get NDIS statistics of network adapter from win32 api specially HardwareFilter value(if promiscuous or not)
thanks.
GeneralprinterAPI for c#.netmemberbalu1234530 Jul '08 - 7:49 
Hi,
 
Iam developing an application/service for printers.The scenario is as follows
 
1. When a user selects a document and then he says the print command(no through my application...he selects normal print in file menu)then i have to catch some details like printername,no.of pages,document name..and so on...This action should be done before it get out from spooler.
 
2. As all of you that after printing data from spooler will be deleted..but in general for example for HP printer 3 files like lpr1234.tmp,shockwaveobject file ,.shd are generated. In this I have take take required files and keep them in my own spooler.

On my extensive search I came to know that by using WMI and WindowsAPI functions I can get to this goal...
 
But Iam unable to get into the right way....
If I have to use APIs then kindly tell what are the method I have to implement(if possible give me documentation link)
 
If through WMI....kindly guide me for the same
 
ALL these should be act as a service.....
 
thanks in Advance
QuestionAPI call to get FAT32 partitionmemberirishrose031228 Nov '07 - 5:36 
I am trying to find the api call for the FAT32 partition on a pen drive. Can anyone help me. I am programming in vb.net. Thanks!
Questionp/invokememberAGraca13 Nov '07 - 5:43 
can you help me? I must implement this API call, but i do not now how to implement this.
 
extern int __stdcall InitSmokeMeter (HINSTANCE hInst, char *port, WNDPROC lpWndProc, HWND *hwnd, long *MsgCode);
 
in parameters:
hInst = handle of application instance
port = string specifying device smokemeter is connected(“COM1”)
lpWinProc = pointer to a standart WindowProc() callback function”
Hwnd = pointer to the handle of the hidden window receiving messages from library
MsgCode = pointer to the message code of message sent by labrary
 
out param:
error code
Hwnd will be set to window handle of the hidden window receiving messages from library
Msgcode will be set to code of message sent by the library
 

 
[DllImport("OpacLib.dll", CharSet = CharSet.Auto)]
static extern int InitSmokeMeter(IntPtr hInst, string port, IntPtr lpWndProc, ref IntPtr hwnd, ref int MsgCode);
 
how can i call this function?
 
thanks...

AnswerRe: p/invokememberkbrryder13 Nov '07 - 18:44 
I am confused. Your declaration looks like it could work. The only paramter im worried about is the WndProc paramter (not sure if it needs to be a special struct or needs to be marshaled as a struct or function pointer possibly). If the declaration is correct then you just call the function you declared as long as your main .exe that is running can see the opaclib.dll in the same path.
AnswerRe: p/invokememberAGraca13 Nov '07 - 23:13 
I am going to try to pass WndProc as a function pointer and see what happends Confused | :confused: .
 
public delegate IntPtr Callback(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
 
[DllImport("OpacLib.dll", CharSet = CharSet.Auto)]
static extern int InitSmokeMeter(IntPtr hInst, string port, Callback lpWndProc, ref IntPtr hwnd, ref int MsgCode);
 
thanks.
GeneralRe: p/invokememberkbrryder14 Nov '07 - 5:11 
I think you might be doing it slighly wrong but I'm not sure, look online for examples of this too.
Generalintegrate a structmemberdark80m25 Sep '07 - 3:17 
Hello,
 
i have a problem to integrate a c/c++ struct into visual c#.
is it possible?
 
Thank you very much
QuestionHow To convert typedef char CONFIG_CTRL[585] in vb.net?memberspierre9 Dec '06 - 12:00 
Hi am trying to import a function from a libarry. The function require a typedef as parameters but everything I have tryed failed.
 
Wow can I declare this type in VB.NET?
typedef char CONFIG_CTRL[585]
 
Thanks.
AnswerRe: How To convert typedef char CONFIG_CTRL[585] in vb.net?memberkbrryder9 Dec '06 - 13:06 
You could try three things, try using a string as a parameter or try using a StringBuilder as a parameter or try using a byte array as a parameter. There are many different ways that might work.
 
-Kyle
Generaldisplay file icons in list viewmemberitbuff8 Nov '06 - 2:26 
I am trying the following code in vc.net
listview = new ListViewItem(ffd.cFileName,0);
HIMAGELIST hSystemSmallImageList;
imageList1 = new ImageList;
SHFILEINFO ssfi;
hSystemSmallImageList = (HIMAGELIST)SHGetFileInfo((LPCTSTR)_T(ffd.cFileName),0,&ssfi,sizeof(SHFILEINFO),SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
System::Drawing::Icon *myIcon = System::Drawing::Icon::FromHandle(ssfi.hIcon);
imageList1->Images->Add(myIcon);
listView1->Items->Add(ffd.cFileName, nIndex++);
 
I get the following error : win32 handle that was passed to Icon is not valid type
GeneralQuestion about exposing HICON via COM C++ that .NET understands ...memberrjschweiger25 Oct '06 - 14:01 
Hi All,
I am in the process of building a COM wrapper using VS2005.VC++ to be used from .NET (C#). One of the methods I need to expose include an HICON parameter.
 
[id(5), helpstring("Set icon content by content identifier")] HRESULT SetContentIcon(ULONG content_id, HICON icon_content);
 
The project compiles find, however when my C# client loads the COM DLL it throws and exception:
 
Unable to cast COM object of type 'SideShowAdapter.CSSManagerClass' to interface type 'SideShowAdapter.ISSManager'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A8E39CE5-274D-4E3E-9247-01F4EE2C3086}' failed due to the following error: Bad variable type. (Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE)).
 
I have narrowed it down to the HICON or I suspect and other handle type that is causing the exception. I have not an advanced C++ programmer. I would appreciate any helpe that you have to offer. Basically what data type can I use to in the method rather than HICON?
 
Thanks in advance.

 
Richard
GeneralRe: Question about exposing HICON via COM C++ that .NET understands ...memberrjschweiger25 Oct '06 - 14:18 
Sorry about the grammer. I should have proof read it before sending it out.
Thanks again.
 
Richard
GeneralRe: Question about exposing HICON via COM C++ that .NET understands ...memberranga@adobe1 Sep '07 - 7:48 
Guys, I am also getting the same error!!!
 
In my case i am getting this error (bad variable type) for
 
[id(3), helpstring("method Reparent")] HRESULT Reparent (HWND wnd);
 
HWND variable.
 
i saw couple of other posts regarding this issue, people are getting this error for struct related parameters ??
 
Any pointers about how to solve this
 
ranga
GeneralGreatmemberscanner7775 Jul '06 - 16:13 
Roll eyes | :rolleyes: Very helpfull, thanx
QuestionHow to pass IntPtr to COM (Help, urgent)memberguocang5 Jul '06 - 11:05 
I am trying to pass some parameters of type Intptr to a COM object. The COM methods need out-going parameters of type int** or byte**. Since the proxy classes generated by VS 2005 requires IntPtr type from the calling method in C#.
 
Can someone tell me how to pass Intptr parameter to get back the int** or byte** data?
 
thanks
 
mike
 

AnswerRe: How to pass IntPtr to COM (Help, urgent)memberkbrryder5 Jul '06 - 11:33 
Well all I can tell you is try using ref or out IntPtr params and then use the static Marshal class to convert your pointers into objects again with casting. There are like 3 different methods in the Marshal class that might do what you want, just take a look, like GetObjectForIUnknown and stuff.
GeneralHelp!Please!memberanders ling12 Jun '06 - 19:39 
I hava a c++ dll Function like this:
unsigned short GX_AddPlayIndexBuffer(char *Buffer,unsigned long Length);
this function need a memory char array data to play,how to call it in C#,
i use [DllImport("GxVoice.dll", CharSet = CharSet.Auto,CallingConvention = CallingConvention.Winapi,SetLastError=true)]
public extern static ushort GX_AddPlayIndexBuffer(char[] Buffer, ulong Length);
or
public extern static ushort GX_AddPlayIndexBuffer(string Buffer, ulong Length);
 
i found it does'nt work!!!this exception is :
A call to PInvoke function 'GXVoiceCSharpLib!GXVoice.GXVoiceAPI::GX_AddPlayIndexBuffer' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
 
why?
Please help~~~~~!!!!!!!
Thanks a lot!
AnswerRe: Help!Please!memberkbrryder13 Jun '06 - 7:21 
Well here are my suggestions seeing as I could find nothing on google whatsoever:
 
change this:
 
[DllImport("GxVoice.dll", CharSet = CharSet.Auto,CallingConvention = CallingConvention.Winapi,SetLastError=true)]
public extern static ushort GX_AddPlayIndexBuffer(char[] Buffer, ulong Length);
 

to this :
 
1.
[DllImport("GxVoice.dll", CharSet = CharSet.Auto,CallingConvention = CallingConvention.Winapi,SetLastError=true)]
public extern static ushort GX_AddPlayIndexBuffer(char[] Buffer, uint Length);
 
or
 
2.
[DllImport("GxVoice.dll", CharSet = CharSet.Auto,CallingConvention = CallingConvention.Winapi,SetLastError=true)]
public extern static ushort GX_AddPlayIndexBuffer(IntPtr Buffer, ulong Length);
 
Marshal a character array into a pointer maybe
 

this is all I can think of

GeneralRe: Help!Please!memberbrian.hawley29 Jul '06 - 2:09 
I happened to notice your example uses the drivers for the Chinese GxVoice card.
 
Did you ever get this working (at all)?
 
I'm playing around with these cards at the moment and can't get the driver to talk to them in any language (including the sample applications).
 
The driver seems to be installed okay and Device Manager says it is working properly. The driver files look to be the right ones. But when I call GX_InitializeSystem (in ANY language) it throws a GX_ERROR_OPEN_DRIVER error.
 
What version of GxVoice.dll do you have? I'm told I have the latest, but it's dated 2002 and I have my doubts. The manufacturer's website is in Chinese of course and not a lot of help, at least to me.
 

 
Brian

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 8 Mar 2005
Article Copyright 2005 by kbrryder
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid