Click here to Skip to main content
15,890,382 members
Home / Discussions / C#
   

C#

 
AnswerRe: Getter and Setter functions Pin
Vikram A Punathambekar23-Apr-07 2:07
Vikram A Punathambekar23-Apr-07 2:07 
QuestionHow to set a parameter field in .rdlc during design time Pin
selvakumar Panchatcharam22-Apr-07 23:57
selvakumar Panchatcharam22-Apr-07 23:57 
QuestionC# time to C++ (VS 6) time Pin
Stevo Z22-Apr-07 23:49
Stevo Z22-Apr-07 23:49 
AnswerRe: C# time to C++ (VS 6) time Pin
Christian Graus23-Apr-07 0:06
protectorChristian Graus23-Apr-07 0:06 
GeneralRe: C# time to C++ (VS 6) time Pin
Stevo Z23-Apr-07 0:15
Stevo Z23-Apr-07 0:15 
QuestionSerialization problem Pin
NaNg1524122-Apr-07 23:48
NaNg1524122-Apr-07 23:48 
QuestionHow to add sub columns with C#.net for Pocket PC Pin
urairat22-Apr-07 23:44
urairat22-Apr-07 23:44 
QuestionMissing something in an unmanaged C++ function call? Pin
jozsurf22-Apr-07 23:26
jozsurf22-Apr-07 23:26 
Hi all,

More trouble with unmanaged code calls from C#: I am trying to call a function in C++ that looks something like this:

int DoSomething(const char* string1,const char* string2,const char* string3,<br />
		const struct1* someStruct, const bool yesno, int* pos, struct2* anotherStruct)


The corresponding wrapper function in C#:

public static extern bool Do_Something(<br />
      [MarshalAs(UnmanagedType.LPStr)] string str1,<br />
      [MarshalAs(UnmanagedType.LPStr)] string str2,<br />
      [MarshalAs(UnmanagedType.LPStr)] string str3,<br />
      StructOne someStruct,<br />
      bool YesNo, <br />
      ref int pos,<br />
      out StructTwo anotherStruct);


The two structs in the unmanaged code (struct1 and struct2) have similar corresponding definitions in the C# code (in this example, called StructOne and StructTwo). These struct defintions are preceded by the following line:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 8)]

Admittedly, I am not quite sure what it does (I'm adding onto someone else's code and am new to C#) but I suppose it has something to do with mapping the C# version of the struct to its C++ counterpart.

The problem: I'm having trouble passing the parameters from the C# wrapper to the C++ routine and am getting AccessViolationExceptions. On stepping through the C++ code, I have found that all the parameters from struct1 onwards are null (the YesNo bool is always false regardless of how it is set in the C# wrapper). All the strings are passed correctly. My feeling is that I have failed to set something up correctly (thus resulting in the program trying to use 'protected' memory), but having checked and rechecked the code (ensuring for instance that there are equivalent members for each of the two C# structs and its corresponding mate in C++), I cannot locate the offending part of the program.

Can anyone help?

thanks Smile | :)
AnswerRe: Missing something in an unmanaged C++ function call? Pin
Luc Pattyn23-Apr-07 9:00
sitebuilderLuc Pattyn23-Apr-07 9:00 
GeneralRe: Missing something in an unmanaged C++ function call? Pin
jozsurf23-Apr-07 14:58
jozsurf23-Apr-07 14:58 
GeneralRe: Missing something in an unmanaged C++ function call? Pin
Luc Pattyn23-Apr-07 15:26
sitebuilderLuc Pattyn23-Apr-07 15:26 
GeneralRe: Missing something in an unmanaged C++ function call? Pin
jozsurf23-Apr-07 15:31
jozsurf23-Apr-07 15:31 
QuestionWrite to the Visual Studio Output window Pin
anderslundsgard22-Apr-07 22:48
anderslundsgard22-Apr-07 22:48 
AnswerRe: Write to the Visual Studio Output window Pin
Christian Graus22-Apr-07 22:54
protectorChristian Graus22-Apr-07 22:54 
GeneralRe: Write to the Visual Studio Output window Pin
anderslundsgard22-Apr-07 22:59
anderslundsgard22-Apr-07 22:59 
QuestionHow to replace colors in a bitmap Pin
dudedotnet22-Apr-07 21:14
dudedotnet22-Apr-07 21:14 
AnswerRe: How to replace colors in a bitmap Pin
Christian Graus22-Apr-07 22:39
protectorChristian Graus22-Apr-07 22:39 
GeneralRe: How to replace colors in a bitmap Pin
dudedotnet26-Apr-07 0:11
dudedotnet26-Apr-07 0:11 
GeneralRe: How to replace colors in a bitmap Pin
Christian Graus26-Apr-07 11:07
protectorChristian Graus26-Apr-07 11:07 
AnswerRe: How to replace colors in a bitmap Pin
Insincere Dave23-Apr-07 8:31
Insincere Dave23-Apr-07 8:31 
QuestionTopmost property not working properly Pin
jorgesalvador22-Apr-07 20:41
jorgesalvador22-Apr-07 20:41 
AnswerRe: Topmost property not working properly Pin
Christian Graus22-Apr-07 22:41
protectorChristian Graus22-Apr-07 22:41 
GeneralRe: Topmost property not working properly Pin
jorgesalvador22-Apr-07 22:58
jorgesalvador22-Apr-07 22:58 
QuestionFace detection algorithm? Pin
tuanlm7522-Apr-07 20:34
tuanlm7522-Apr-07 20:34 
AnswerRe: Face detection algorithm? Pin
Christian Graus22-Apr-07 22:44
protectorChristian Graus22-Apr-07 22:44 

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.