473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Calling dll functions

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.
Apr 20 '06 #1
4 2236
Try StringBuilder instead of string type.

John wrote:
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.

Apr 20 '06 #2

"John" <Jo**@discussions.microsoft.com> wrote in message
news:0F**********************************@microsof t.com...
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

Apr 20 '06 #3
sb
btw: you don't need to declare "Num" as an out parameter unless the DLL
plans to change it.

-sb

"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:uD**************@TK2MSFTNGP05.phx.gbl...

"John" <Jo**@discussions.microsoft.com> wrote in message
news:0F**********************************@microsof t.com...
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

Apr 20 '06 #4

"sb" <st********@yahoo.com> wrote in message
news:u7**************@TK2MSFTNGP04.phx.gbl...
btw: you don't need to declare "Num" as an out parameter unless the DLL
plans to change it.

-sb

"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:uD**************@TK2MSFTNGP05.phx.gbl...

"John" <Jo**@discussions.microsoft.com> wrote in message
news:0F**********************************@microsof t.com...
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

Apr 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: pieter.breed | last post by:
Hi All, Is it possible to export a c# method into a dll in such a way that your "normal" C application can then call this method? To be clear: I am not asking how to use "DllImport" or...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
5
by: Dave | last post by:
does calling a regular function cost any cpu time? In other words, is it faster to write the code of two functions into main(), or is it the exact same thing as calling two functions. I know its...
1
by: Mark Jerde | last post by:
Yesterday I posted the message below to microsoft.public.dotnet.languages.vb and microsoft.public.vc.language. The two replies are also posted. I need to write some ISO C++ functions, more...
1
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code...
1
by: H.B. | last post by:
Hi, I need to make a function that can display data on my Managed C++ app and be called by an unmanaged C++ DLL. Something like : void Form1::Form1_Load(System::Object * sender,...
2
by: Daniel Lidström | last post by:
I'm using a library called fyba. This library reads and writes files in a format called sosi. fyba uses the following code to determine if the calling process has own methods to handle errors,...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
10
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.