Click here to Skip to main content
15,891,567 members
Home / Discussions / C#
   

C#

 
GeneralRe: When main thread working the Whole Form Freezes Pin
Sean893-Mar-06 14:09
Sean893-Mar-06 14:09 
AnswerRe: When main thread working the Whole Form Freezes Pin
LighthouseJ3-Mar-06 16:11
LighthouseJ3-Mar-06 16:11 
QuestionRS232 Serial Class with .NET 2.0 Pin
econner3-Mar-06 12:13
econner3-Mar-06 12:13 
AnswerRe: RS232 Serial Class with .NET 2.0 Pin
Office Lineman3-Mar-06 13:39
Office Lineman3-Mar-06 13:39 
GeneralRe: RS232 Serial Class with .NET 2.0 Pin
econner4-Mar-06 2:02
econner4-Mar-06 2:02 
QuestionGraph ploting.. Pin
KORCARI3-Mar-06 10:20
KORCARI3-Mar-06 10:20 
AnswerRe: Graph ploting.. Pin
Curtis Schlak.3-Mar-06 15:04
Curtis Schlak.3-Mar-06 15:04 
QuestionCall C# DLL from (unmanaged) C++: question on passing out string parameter Pin
Koushik Biswas3-Mar-06 10:01
Koushik Biswas3-Mar-06 10:01 
I have written a C# DLL that I intend to call from an unmanaged C++ app. I have so far followed all the rules that Microsoft explains in this article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkcominteroppart2cservertutorial.asp[^]. My ultimate goal is to have a method in the C# DLL which will populate a string OUT parameter, and call it from C++. Something like void GetErrorString( int iErrorCode, ref string szErrorString ). Now do not take that signature seriously - because that is what the question is! What should be the signature???? And how exactly do I call it from C++?

So far I have tried:

Attempt 1.
C# signature:
void Func2( int iCode, ref char [] szOut );
C++ call:
char szRetString[ 128 ];<br />
cpi->Func2( 10, &szRetString );

Result: Runtime error
Variation: Instead of "&szRetString" in C++, tried "szRetString". Same result.
Variation: Instead of "ref" in C#, tried without ref. Same result.

Attempt 2.
C# signature:
void Func2( int iCode, ref string szOut );
C++ call:
char szRetString[ 128 ];<br />
cpi->Func2( 10, &szRetString );

Result: Runtime error
Variation: Instead of "&szRetString" in C++, tried "szRetString". Same result.
Variation: Instead of "ref" in C#, tried without ref. Same result.

Attempt 3.
C# signature:
void Func2( int iCode, ref StringBuilder szOut );
C++ call:
char szRetString[ 128 ];<br />
cpi->Func2( 10, &szRetString );

Result: Runtime error
Variation: Instead of "&szRetString" in C++, tried "szRetString". Same result.
Variation: Instead of "ref" in C#, tried without ref. Same result.

And all the cross-variations of the above combinations as well!!!!

Can somebody please tell me where am I going wrong? My C++ project does not have UNICODE defined. But please note that I have succeeded in calling the example provided by the MSDN article (link above) - which means I am successful in sending a read - only copy of string as IN parameter into C#.

Ever wondered that microsoft examples avoid the harder part?;)


Koushik Biswas
If you would not be forgotten as soon as you are dead...
either write things worth reading or do things worth writing.

AnswerRe: Call C# DLL from (unmanaged) C++: question on passing out string parameter Pin
Rob Graham3-Mar-06 10:25
Rob Graham3-Mar-06 10:25 
QuestionWant to draw continuous line based on a function Pin
...---...3-Mar-06 9:40
...---...3-Mar-06 9:40 
AnswerRe: Want to draw continuous line based on a function Pin
Robert Rohde3-Mar-06 10:24
Robert Rohde3-Mar-06 10:24 
QuestionRegular expressions in C# Pin
Martin233-Mar-06 9:35
Martin233-Mar-06 9:35 
AnswerRe: Regular expressions in C# Pin
Robert Rohde3-Mar-06 10:29
Robert Rohde3-Mar-06 10:29 
GeneralRe: Regular expressions in C# Pin
Martin233-Mar-06 10:52
Martin233-Mar-06 10:52 
QuestionRepaint Entire Component not Invalidate Pin
nickbungus3-Mar-06 8:03
nickbungus3-Mar-06 8:03 
AnswerRe: Repaint Entire Component not Invalidate Pin
Robert Rohde3-Mar-06 10:31
Robert Rohde3-Mar-06 10:31 
GeneralRe: Repaint Entire Component not Invalidate Pin
nickbungus3-Mar-06 22:17
nickbungus3-Mar-06 22:17 
Questionthe future of c#.net Pin
mostafa_h3-Mar-06 7:08
mostafa_h3-Mar-06 7:08 
AnswerRe: the future of c#.net Pin
User 66583-Mar-06 8:12
User 66583-Mar-06 8:12 
AnswerRe: the future of c#.net Pin
Dave Kreskowiak3-Mar-06 13:52
mveDave Kreskowiak3-Mar-06 13:52 
GeneralRe: the future of c#.net Pin
mostafa_h4-Mar-06 9:28
mostafa_h4-Mar-06 9:28 
QuestionRemove space Pin
ap_sa3-Mar-06 6:08
ap_sa3-Mar-06 6:08 
AnswerRe: Remove space Pin
Guffa3-Mar-06 6:31
Guffa3-Mar-06 6:31 
GeneralRe: Remove space Pin
ap_sa3-Mar-06 7:42
ap_sa3-Mar-06 7:42 
QuestionPrint Treeview, C#.NET 2005 Pin
JGIS3-Mar-06 4:37
JGIS3-Mar-06 4:37 

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.