Click here to Skip to main content
15,915,508 members
Home / Discussions / C#
   

C#

 
Questiondisplaying images from a xml file Pin
diducmy28-Mar-07 5:35
diducmy28-Mar-07 5:35 
AnswerRe: displaying images from a xml file Pin
Martin#28-Mar-07 5:56
Martin#28-Mar-07 5:56 
QuestionXmlSerializer and CDATA Pin
theJazzyBrain28-Mar-07 5:15
theJazzyBrain28-Mar-07 5:15 
QuestionConverting a string to currency format Pin
lee.hallows28-Mar-07 5:09
lee.hallows28-Mar-07 5:09 
AnswerRe: Converting a string to currency format Pin
joon vh.28-Mar-07 5:17
joon vh.28-Mar-07 5:17 
QuestionUsing reference parameters when calling an exposed function from a DLL Pin
Dewald28-Mar-07 5:09
Dewald28-Mar-07 5:09 
AnswerRe: Using reference parameters when calling an exposed function from a DLL Pin
m@u28-Mar-07 5:29
m@u28-Mar-07 5:29 
GeneralRe: Using reference parameters when calling an exposed function from a DLL Pin
Dewald28-Mar-07 23:39
Dewald28-Mar-07 23:39 
Thanks m@u. I was afraid it might have something to do with Marshaling because I bumped into that once before and never really figured it out. I suppose I still don't understand this whole managed memory versus unmanaged memory thing.

At any rate, I tried your suggestion and read up on the MarshalAs attribute but it still didn't solve my problem and I still don't think I really understand how to use this MarshalAs attribute but to my great relief, the solution to my problem popped out of virtually nowhere.

The C++ programmer in me still pondered on this principle of passing pointers as funtion parameters and it occured to me that, if in C++ passing an array and passing a pointer is one and the same thing, doesn't the same apply for C# and reference parameters?

So I changed my function declaration which follows the DLLImport attribute from:
public static extern int sendAPDU(Byte[] TxAPDU, int TxLen, ref Byte[] RxAPDU, ref int RxLen);
to:
public static extern int sendAPDU(Byte[] TxAPDU, int TxLen, Byte[] RxAPDU, ref int RxLen);
and would you believe it, it works!

I'm still unsure about the memory management issue that this introduces. In C++ this would have left room for serious memory overflow issues, so what happens in C# if you call a function from a DLL written in C++? Let's say, I have a function like this:
public static extern int myFunc(byte[] ByteArray);
which, in the DLL, does something like this:
ByteArray[10] = 10;

Now, if you call this from C# like this:
byte[] sendArray = { 1, 2, 3 };<br />
int retval = myFunc(sendArray);


Clearly in C++ this would have written the value 10 into memory, 7 bytes past the end of the memory allocated to sendArray, causing havoc. So what happens when you call the DLL function from C#?

Sorry guys, I realise that this is one of the central issues to C# and you can't claim to be a C# programmer if you don't understand managed vs. unmanaged memory. But I am a noob.
QuestionGuidance Automation Toolkit or CodeSmith? Pin
wojti28-Mar-07 5:03
wojti28-Mar-07 5:03 
Questioncalling function in parent form from child form Pin
Lordveralix28-Mar-07 4:13
Lordveralix28-Mar-07 4:13 
AnswerRe: calling function in parent form from child form Pin
Pete O'Hanlon28-Mar-07 4:22
mvePete O'Hanlon28-Mar-07 4:22 
GeneralRe: calling function in parent form from child form Pin
Lordveralix28-Mar-07 4:51
Lordveralix28-Mar-07 4:51 
GeneralRe: calling function in parent form from child form Pin
Pete O'Hanlon28-Mar-07 4:54
mvePete O'Hanlon28-Mar-07 4:54 
GeneralRe: calling function in parent form from child form Pin
Lordveralix28-Mar-07 5:13
Lordveralix28-Mar-07 5:13 
GeneralRe: calling function in parent form from child form Pin
Lordveralix28-Mar-07 7:11
Lordveralix28-Mar-07 7:11 
Question[Message Deleted] Pin
pashitech28-Mar-07 3:56
pashitech28-Mar-07 3:56 
AnswerRe: how to find help tools Pin
Judah Gabriel Himango28-Mar-07 4:06
sponsorJudah Gabriel Himango28-Mar-07 4:06 
AnswerRe: how to find help tools Pin
Judah Gabriel Himango28-Mar-07 4:55
sponsorJudah Gabriel Himango28-Mar-07 4:55 
GeneralRe: how to find help tools Pin
pashitech28-Mar-07 5:36
pashitech28-Mar-07 5:36 
QuestionREMOTE INSTALL Pin
waddah_com28-Mar-07 3:55
waddah_com28-Mar-07 3:55 
AnswerRe: REMOTE INSTALL Pin
Judah Gabriel Himango28-Mar-07 4:05
sponsorJudah Gabriel Himango28-Mar-07 4:05 
AnswerRe: REMOTE INSTALL Pin
Judah Gabriel Himango28-Mar-07 4:57
sponsorJudah Gabriel Himango28-Mar-07 4:57 
AnswerRe: REMOTE INSTALL Pin
Vasudevan Deepak Kumar28-Mar-07 7:52
Vasudevan Deepak Kumar28-Mar-07 7:52 
GeneralRe: REMOTE INSTALL Pin
waddah_com30-Mar-07 4:23
waddah_com30-Mar-07 4:23 
QuestionSelecting item in listbox after creating it Pin
sinosoidal28-Mar-07 3:54
sinosoidal28-Mar-07 3:54 

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.