Calling dll functions

G

Guest

DWORD _stdcall DLLFunction(DWORD Num, CHAR *Str);

I call the above dll function from a C++ app. Now I need to call it from my
C# app. How can I do it?

[DllImport("MyDll.dll")]
public static extern int DLLFunction(int Num, string Info);

int Num;
string Info = new string(' ', 80);
DLLFunction(Num, Info);

I cannot get anything in variable Info. Please help. Thanks.
 
M

Mythran

John said:
DWORD _stdcall DLLFunction(DWORD Num, CHAR *Str);

I call the above dll function from a C++ app. Now I need to call it from
my
C# app. How can I do it?

[DllImport("MyDll.dll")]
public static extern int DLLFunction(int Num, string Info);

int Num;
string Info = new string(' ', 80);
DLLFunction(Num, Info);

I cannot get anything in variable Info. Please help. Thanks.

[DllImport("myDll.dll")]
public static extern int DLLFunction(out int Num, StringBuilder Info);

int Num;
string Info = new StringBuilder(80);
DLLFunction(out Num, Info);
string results = Info.ToString();

HTH,
Mythran
 
S

sb

btw: you don't need to declare "Num" as an out parameter unless the DLL
plans to change it.

-sb

Mythran said:
John said:
DWORD _stdcall DLLFunction(DWORD Num, CHAR *Str);

I call the above dll function from a C++ app. Now I need to call it from
my
C# app. How can I do it?

[DllImport("MyDll.dll")]
public static extern int DLLFunction(int Num, string Info);

int Num;
string Info = new string(' ', 80);
DLLFunction(Num, Info);

I cannot get anything in variable Info. Please help. Thanks.

[DllImport("myDll.dll")]
public static extern int DLLFunction(out int Num, StringBuilder Info);

int Num;
string Info = new StringBuilder(80);
DLLFunction(out Num, Info);
string results = Info.ToString();

HTH,
Mythran
 
M

Mythran

sb said:
btw: you don't need to declare "Num" as an out parameter unless the DLL
plans to change it.

-sb

Mythran said:
John said:
DWORD _stdcall DLLFunction(DWORD Num, CHAR *Str);

I call the above dll function from a C++ app. Now I need to call it from
my
C# app. How can I do it?

[DllImport("MyDll.dll")]
public static extern int DLLFunction(int Num, string Info);

int Num;
string Info = new string(' ', 80);
DLLFunction(Num, Info);

I cannot get anything in variable Info. Please help. Thanks.

[DllImport("myDll.dll")]
public static extern int DLLFunction(out int Num, StringBuilder Info);

int Num;
string Info = new StringBuilder(80);
DLLFunction(out Num, Info);
string results = Info.ToString();

HTH,
Mythran

Well, if he compiled it as it was, he would get a compile-time error since
Num has not been initialize, which is why I set it to "out" instead...but I
should have noted that :)

Mythran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top