Click here to Skip to main content
15,900,378 members
Home / Discussions / C#
   

C#

 
QuestionSerialize an Array with ISerializable? Pin
huckfinn27-Jan-05 3:18
huckfinn27-Jan-05 3:18 
AnswerRe: Serialize an Array with ISerializable? Pin
Heath Stewart27-Jan-05 9:59
protectorHeath Stewart27-Jan-05 9:59 
Generaltrouble deleting records from my sql server Pin
tadhg8827-Jan-05 3:17
tadhg8827-Jan-05 3:17 
GeneralRe: trouble deleting records from my sql server Pin
Mazdak28-Jan-05 0:53
Mazdak28-Jan-05 0:53 
GeneralRe: Time Validation in C# Pin
Mazdak27-Jan-05 2:01
Mazdak27-Jan-05 2:01 
GeneralRe: Time Validation in C# Pin
itssuk27-Jan-05 3:01
itssuk27-Jan-05 3:01 
GeneralTime Validation in C# Pin
itssuk27-Jan-05 1:17
itssuk27-Jan-05 1:17 
GeneralNeed help with C# to C++ DLL interaction Pin
lms00727-Jan-05 0:55
lms00727-Jan-05 0:55 
EDIT: This problem is solved!

I'm building an application partly in C# (which I am learning currently) and the other part in C++.
What I want to do is pass a string or array of char's form my C++ dll to my C# exe. I seem to be able to pass basic data types, but when it comes to pointers or Strings or anything else, it either doest work, or my heap gets messed up or overwritten.


here is what I have in my C++ project
EXPORT void TestFunc(char* str)
{
     str = ptr; //(some memory over here)
}


here is the C# stuff

[DllImport("My_C_PlusPlus.dll")]
public static extern void TestFunc( [MarshalA(UnmanagedType.LPTStr)] StringBuilder str);

StringBuilder temp = new StringBuilder(128);
TestFunc(temp);

and temp ends up NOT being correct;

But I tried this too

C++..
EXPORT char* TestFunc()
{
return ptr //(some memory over here)
}


C#...
String temp = TestFunc();  

temp ends up being correct weather it’s a String or StringBuiler, but then my heap for my c++ dll gets jacked. I get an int 3 (user defined break) right away upon returning that function;

I also tried just using a char* in my C# project and assigning upon return from the dll function call but that didn’t work at all, the value ended up being all message. The problem is, one project thinks is some datatype and the other thinks its something else, so it never works. Is there some sort of unified data type for strings or pointers to strings that I can use here?
GeneralRe: Need help with C# to C++ DLL interaction Pin
lms00727-Jan-05 1:53
lms00727-Jan-05 1:53 
GeneralRe: Need help with C# to C++ DLL interaction Pin
lms00727-Jan-05 2:17
lms00727-Jan-05 2:17 
GeneralNo overload for method Pin
nikneem200526-Jan-05 23:15
nikneem200526-Jan-05 23:15 
GeneralRe: No overload for method Pin
Stefan Troschuetz26-Jan-05 23:39
Stefan Troschuetz26-Jan-05 23:39 
GeneralRe: No overload for method Pin
J4amieC27-Jan-05 0:08
J4amieC27-Jan-05 0:08 
GeneralRe: No overload for method Pin
nikneem200527-Jan-05 0:19
nikneem200527-Jan-05 0:19 
GeneralRe: No overload for method Pin
J4amieC27-Jan-05 0:03
J4amieC27-Jan-05 0:03 
GeneralSecurity error - windows custom control Pin
26-Jan-05 23:00
suss26-Jan-05 23:00 
GeneralConnection pooling in windows.net Pin
sapnabn26-Jan-05 22:59
sapnabn26-Jan-05 22:59 
GeneralRe: Connection pooling in windows.net Pin
Member 37818926-Jan-05 23:07
Member 37818926-Jan-05 23:07 
GeneralCapturing Video Pin
Deobrat Singh26-Jan-05 22:43
Deobrat Singh26-Jan-05 22:43 
GeneralServicedComponent object in server process Pin
kianboo26-Jan-05 21:27
kianboo26-Jan-05 21:27 
GeneralWindows login Pin
sharathgowda26-Jan-05 20:14
sharathgowda26-Jan-05 20:14 
GeneralRe: Windows login Pin
26-Jan-05 21:34
suss26-Jan-05 21:34 
GeneralRe: Windows login Pin
sharathgowda27-Jan-05 0:58
sharathgowda27-Jan-05 0:58 
GeneralRe: Windows login Pin
Dave Kreskowiak27-Jan-05 4:18
mveDave Kreskowiak27-Jan-05 4:18 
GeneralUpdating a database from a complex DataSet Pin
Luis Alonso Ramos26-Jan-05 18:11
Luis Alonso Ramos26-Jan-05 18:11 

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.