Click here to Skip to main content
15,921,837 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem With sending values via serial port Pin
Bernhard Hiller23-Mar-11 22:05
Bernhard Hiller23-Mar-11 22:05 
GeneralRe: Problem With sending values via serial port Pin
phil.o24-Mar-11 4:56
professionalphil.o24-Mar-11 4:56 
AnswerRe: Problem With sending values via serial port Pin
Sader_L25-Mar-11 3:21
Sader_L25-Mar-11 3:21 
QuestionReceipt Printing Pin
Wamuti22-Mar-11 6:19
Wamuti22-Mar-11 6:19 
AnswerRe: Receipt Printing Pin
TheyCallMeMrJames22-Mar-11 6:47
TheyCallMeMrJames22-Mar-11 6:47 
AnswerRe: Receipt Printing Pin
Dalek Dave22-Mar-11 10:50
professionalDalek Dave22-Mar-11 10:50 
AnswerRe: Receipt Printing Pin
lorenkins23-Mar-11 7:00
lorenkins23-Mar-11 7:00 
QuestionChar* in C++ 6 to C# .Net [modified] Pin
KeithF22-Mar-11 4:06
KeithF22-Mar-11 4:06 
Hi Guys,

I have a DLL created in Visual Studio 6 / C++ with the following function

MyDLL_API int __stdcall MyMethod( char *strA, char *strB, char *strC )


i am trying to reference it like so in c# 2005

[DllImport("mydll.dll", CharSet = CharSet.Auto)]
        public static extern int MyMethod(ref string strA, ref string strB, ref string strC);


Here is the debugging code i added to MyMethod but the params are garbage when presented on screen:

MyDLL_API int __stdcall MyMethod( char *strA, char *strB, char *strC )	
        int   ret_val            = 0;
	char  cA[161]   = {0};
	char  cB[161] = {0};
	char  cC[161]   = {0};
	LPSTR buffer             = NULL;
	char  cMsg[161] = {0};

	buffer = (LPSTR)strA;
	strncpy( cA, buffer, 161);

	buffer = (LPSTR)strB;
	strncpy( cB, buffer, 161);

	buffer = (LPSTR)strC;
	strncpy( cC, buffer, 161);

	sprintf( cMsg, "Params A=%s,B=%s,C=%s", strA, strB, strC );
	MessageBox( NULL, cMsg, "Dispense", MB_OK );



the function gets called but all i see is garbage in the parameters passed in, other than a string what else can i use to pass to the Char*?

Thanks In Advance

modified on Tuesday, March 22, 2011 10:29 AM

AnswerRe: Char* in C++ 6 to C# .Net Pin
Richard MacCutchan22-Mar-11 4:34
mveRichard MacCutchan22-Mar-11 4:34 
GeneralRe: Char* in C++ 6 to C# .Net Pin
KeithF22-Mar-11 4:40
KeithF22-Mar-11 4:40 
GeneralRe: Char* in C++ 6 to C# .Net Pin
Richard MacCutchan22-Mar-11 5:10
mveRichard MacCutchan22-Mar-11 5:10 
AnswerRe: Char* in C++ 6 to C# .Net Pin
KeithF22-Mar-11 4:37
KeithF22-Mar-11 4:37 
GeneralRe: Char* in C++ 6 to C# .Net Pin
Richard MacCutchan22-Mar-11 5:13
mveRichard MacCutchan22-Mar-11 5:13 
GeneralRe: Char* in C++ 6 to C# .Net Pin
KeithF22-Mar-11 5:30
KeithF22-Mar-11 5:30 
GeneralRe: Char* in C++ 6 to C# .Net Pin
Richard MacCutchan22-Mar-11 8:16
mveRichard MacCutchan22-Mar-11 8:16 
GeneralRe: Char* in C++ 6 to C# .Net Pin
Ian Shlasko22-Mar-11 5:32
Ian Shlasko22-Mar-11 5:32 
AnswerRe: Char* in C++ 6 to C# .Net [modified] Pin
Luc Pattyn22-Mar-11 6:16
sitebuilderLuc Pattyn22-Mar-11 6:16 
GeneralRe: Char* in C++ 6 to C# .Net Pin
KeithF22-Mar-11 6:24
KeithF22-Mar-11 6:24 
AnswerRe: Char* in C++ 6 to C# .Net Pin
Luc Pattyn22-Mar-11 6:31
sitebuilderLuc Pattyn22-Mar-11 6:31 
GeneralRe: Char* in C++ 6 to C# .Net Pin
KeithF22-Mar-11 6:40
KeithF22-Mar-11 6:40 
Questionclickonce Deployment [modified] Pin
arkiboys22-Mar-11 3:40
arkiboys22-Mar-11 3:40 
AnswerRe: clickonce Deployment Pin
Dave Kreskowiak22-Mar-11 4:47
mveDave Kreskowiak22-Mar-11 4:47 
GeneralRe: clickonce Deployment Pin
arkiboys22-Mar-11 4:51
arkiboys22-Mar-11 4:51 
GeneralRe: clickonce Deployment Pin
Rajesh R Subramanian23-Mar-11 4:47
professionalRajesh R Subramanian23-Mar-11 4:47 
GeneralRe: clickonce Deployment Pin
Dave Kreskowiak23-Mar-11 12:12
mveDave Kreskowiak23-Mar-11 12:12 

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.