Click here to Skip to main content
15,910,118 members
Home / Discussions / C#
   

C#

 
GeneralRe: type conversion Pin
egon3-Mar-03 8:00
egon3-Mar-03 8:00 
QuestionDraw a rectangle in a richtextbox? Pin
red2k3-Mar-03 2:25
red2k3-Mar-03 2:25 
AnswerRe: Draw a rectangle in a richtextbox? Pin
jtmtv183-Mar-03 6:39
jtmtv183-Mar-03 6:39 
Questionvoid* interop? Pin
Anonymous2-Mar-03 19:55
Anonymous2-Mar-03 19:55 
AnswerRe: void* interop? Pin
Jeff J2-Mar-03 21:16
Jeff J2-Mar-03 21:16 
GeneralRe: void* interop? Pin
Anonymous3-Mar-03 2:04
Anonymous3-Mar-03 2:04 
GeneralRe: void* interop? Pin
leppie3-Mar-03 7:06
leppie3-Mar-03 7:06 
GeneralRe: void* interop? Pin
Jeff J4-Mar-03 14:36
Jeff J4-Mar-03 14:36 
As leppie posted, there are many useful functions in the Marshal class, which is good to become familiar with if you are interfacing with external C or C++ functions. IntPtr itself also has useful methods, such as ToPointer() and ToInt32(), along with the statics Zero and operator overloads that can convert between void pointers and IntPtr types. Which ones to use depends on how you plan on calling the extern functions.

It is hard to explain the usage details without seeing a code example. If you could post one with how the calls are intended to be made, and how the parameters are to be passed, I'm sure I could explain a solution.

Regarding using the extern funcs you currently have, if the calling C# func is declared unsafe, then you can just cast your "ints" as in regular C code (including pointers and taking addresses). Or you can prototype the externs as unsafe from the start like:

DLLImport("rv.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl))
public static extern unsafe int f(void *pVoid);

DLLImport("rv.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl))
public static extern unsafe int f2(void **ppVoid);


If you are looking to do this using the non-unsafe runtime interop features, you could do:

DLLImport("rv.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl))
public static extern int f(IntPtr pVoid);

DLLImport("rv.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl))
public static extern int f2(IntPtr ppVoid);

GeneralInterop - Marshaling nested structs Pin
Nathan Tran2-Mar-03 19:01
Nathan Tran2-Mar-03 19:01 
GeneralRe: Interop - Marshaling nested structs Pin
leppie3-Mar-03 7:38
leppie3-Mar-03 7:38 
GeneralRe: Interop - Marshaling nested structs Pin
Nathan Tran3-Mar-03 11:56
Nathan Tran3-Mar-03 11:56 
GeneralRe: Interop - Marshaling nested structs Pin
leppie4-Mar-03 7:03
leppie4-Mar-03 7:03 
GeneralHowto: image to byte array Pin
Smitha Nishant2-Mar-03 18:56
protectorSmitha Nishant2-Mar-03 18:56 
GeneralRe: Howto: image to byte array Pin
Jeff J2-Mar-03 21:26
Jeff J2-Mar-03 21:26 
GeneralRe: Howto: image to byte array Pin
Smitha Nishant2-Mar-03 22:10
protectorSmitha Nishant2-Mar-03 22:10 
General***capturing image from video*** Pin
henrykao2-Mar-03 18:37
henrykao2-Mar-03 18:37 
QuestionCan you use resources to embed a wav? Pin
jtmtv182-Mar-03 13:48
jtmtv182-Mar-03 13:48 
AnswerRe: Can you use resources to embed a wav? Pin
leppie3-Mar-03 8:02
leppie3-Mar-03 8:02 
GeneralRe: Can you use resources to embed a wav? Pin
jtmtv183-Mar-03 8:32
jtmtv183-Mar-03 8:32 
GeneralRe: Can you use resources to embed a wav? Pin
leppie4-Mar-03 6:57
leppie4-Mar-03 6:57 
GeneralAeru IRC is looking for developpers and artist Pin
Shock The Dark Mage2-Mar-03 12:46
Shock The Dark Mage2-Mar-03 12:46 
GeneralRe: Aeru IRC is looking for developpers and artist Pin
jtmtv183-Mar-03 19:17
jtmtv183-Mar-03 19:17 
GeneralRe: Aeru IRC is looking for developpers and artist Pin
Shock The Dark Mage5-Mar-03 15:47
Shock The Dark Mage5-Mar-03 15:47 
GeneralFlattening The TreeView... Pin
LokiSD2-Mar-03 10:26
LokiSD2-Mar-03 10:26 
GeneralRe: Flattening The TreeView... Pin
LokiSD3-Mar-03 7:42
LokiSD3-Mar-03 7:42 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.