how to wrap some dll functions from VC6
-
Hi, everyone I am using a dll developped in VC6. There are some functions I don't know how to wrap it in C#. 1. one function's parameter use self defined type, type definition is like this: #ifndef LPLONG typedef long far *LPLONG; /* 32 bit */ #endif 2. one function's parameter use 'BOOL *' 3. one function's parameter use 'char *' 4. one function's return value use 'char *' 5. one function's parameter use a structure 6. one function's parameter use a structure * How shall I deal with these? Thanks in advance.
-
Hi, everyone I am using a dll developped in VC6. There are some functions I don't know how to wrap it in C#. 1. one function's parameter use self defined type, type definition is like this: #ifndef LPLONG typedef long far *LPLONG; /* 32 bit */ #endif 2. one function's parameter use 'BOOL *' 3. one function's parameter use 'char *' 4. one function's return value use 'char *' 5. one function's parameter use a structure 6. one function's parameter use a structure * How shall I deal with these? Thanks in advance.
1.
ref int
2.ref bool
3.[MarshalAs(UnmanagedType.LPStr)]string
4.[return: MarshalAs(UnmanagedType.LPStr)]string
5. Just pass the struct, but see the docs for theStructLayoutAttribute
6.ref _YourStruct_
All these - escept for 3 and 4 - are value types so you useref
orout
(the latter if you don't need to pass any initial value to your functions). Don't useref
orout
with a string because it is already a reference type. Bothchar*
andchar[]
are strings since a string is only an array of characters. Since you're usingchar
and notwchar_t
(orTCHAR
), you must marshal them as ANSI strings.Microsoft MVP, Visual C# My Articles
-
1.
ref int
2.ref bool
3.[MarshalAs(UnmanagedType.LPStr)]string
4.[return: MarshalAs(UnmanagedType.LPStr)]string
5. Just pass the struct, but see the docs for theStructLayoutAttribute
6.ref _YourStruct_
All these - escept for 3 and 4 - are value types so you useref
orout
(the latter if you don't need to pass any initial value to your functions). Don't useref
orout
with a string because it is already a reference type. Bothchar*
andchar[]
are strings since a string is only an array of characters. Since you're usingchar
and notwchar_t
(orTCHAR
), you must marshal them as ANSI strings.Microsoft MVP, Visual C# My Articles
-
IntPtr
Microsoft MVP, Visual C# My Articles