Click here to Skip to main content
15,887,945 members
Home / Discussions / C#
   

C#

 
GeneralRe: package and deployment related question Pin
sumeat18-Sep-03 15:24
sumeat18-Sep-03 15:24 
GeneralRe: package and deployment related question Pin
Braulio Dez19-Sep-03 2:19
Braulio Dez19-Sep-03 2:19 
Questionhow to loop in control collection?? Pin
Tridip Bhattacharjee17-Sep-03 4:13
professionalTridip Bhattacharjee17-Sep-03 4:13 
AnswerRe: how to loop in control collection?? Pin
Mazdak17-Sep-03 7:53
Mazdak17-Sep-03 7:53 
Questionhow to handle click event for a multiple button ?? Pin
Tridip Bhattacharjee17-Sep-03 4:00
professionalTridip Bhattacharjee17-Sep-03 4:00 
AnswerRe: how to handle click event for a multiple button ?? Pin
MrEyes17-Sep-03 4:28
MrEyes17-Sep-03 4:28 
GeneralWhy disable debug Pin
Old Gun17-Sep-03 3:37
Old Gun17-Sep-03 3:37 
Generalinterop struct types Pin
Tym!17-Sep-03 2:59
Tym!17-Sep-03 2:59 
I have a struct to mimic a c++ struct...I have converted types as follows:
C++ C#
---- ----
WORD ushort
DWORD uint
char[] string

the imported function passes a pointer to the struct, fills it with fun-facts and gives it back more useful than before. The only thing I currently want out of this is the char[] member of the struct and things are not working out.

Here's what I have done:
- I am using CharSet.Auto in the structLayout and dllImport attributes.
- in the function prototype : "ref STRUCTTYPE structname"
- before calling the function, initializing struct by using "new"
- before calling the function, initializing the string by creating a StringBuilder buffer of appropriate size and "ToString-ing" it to the struct.string member.

problem is, when I call the function and access the string, it still contains the text that I used to initialize it in the first place.

I haven't done enough testing to determine the problem, but I wanted to see if you have any ideas. My first question is to verify that using a c# string to represent the c++ char[] is all cool. I think it should be.
[Edit]Sigh | :sigh: Almost, need [MarshalAs(UnmanagedType.ByValTStr, SizeConst=256] because it is a fixed char array [/Edit]

What I was thinking of while typing right now, is this:
in c++ structs are reference variables. in c# they are value variables. if i wanted to pass a c# struct to a c++ function, i would use the ref modifyer. Since my function wants a pointer to the struct, should I be using something like "ref IntPtr structname" ???? is this my problem and my solution?
[Edit]D'Oh! | :doh: not quite, should work with "ref STRUCTTYPE structname"... if the struct were represented using a class, then would need [In,Out] instead of ref. See link in next post for details. Can't wait to get home and try it![/Edit]

Tym!
GeneralMarshaling Structs Reference Pin
Tym!17-Sep-03 4:26
Tym!17-Sep-03 4:26 
GeneralEditable ListView items Pin
Rickard Andersson2017-Sep-03 1:28
Rickard Andersson2017-Sep-03 1:28 
GeneralRe: Editable ListView items Pin
JoeGunchy17-Sep-03 9:22
JoeGunchy17-Sep-03 9:22 
GeneralRe: Editable ListView items Pin
Rickard Andersson2017-Sep-03 10:46
Rickard Andersson2017-Sep-03 10:46 
GeneralWindows service, OnShutDown not executed Pin
EnkelIk16-Sep-03 23:18
EnkelIk16-Sep-03 23:18 
GeneralRe: Windows service, OnShutDown not executed Pin
EnkelIk16-Sep-03 23:36
EnkelIk16-Sep-03 23:36 
GeneralKeyboard hooks - Problem Pin
CyberKewl16-Sep-03 22:21
CyberKewl16-Sep-03 22:21 
Generalunicode in c# Pin
Anonymous16-Sep-03 21:13
Anonymous16-Sep-03 21:13 
GeneralRe: unicode in c# Pin
Oleksandr Kucherenko17-Sep-03 0:02
Oleksandr Kucherenko17-Sep-03 0:02 
GeneralOne ScrollBar controls two DataViews Pin
JoeGunchy16-Sep-03 14:40
JoeGunchy16-Sep-03 14:40 
GeneralC# is the best Pin
Snyp16-Sep-03 12:13
Snyp16-Sep-03 12:13 
GeneralRe: C# is the best Pin
Rickard Andersson2017-Sep-03 1:30
Rickard Andersson2017-Sep-03 1:30 
GeneralRe: C# is the best Pin
Snyp17-Sep-03 1:42
Snyp17-Sep-03 1:42 
GeneralRe: C# is the best Pin
Rickard Andersson2017-Sep-03 2:42
Rickard Andersson2017-Sep-03 2:42 
GeneralRe: C# is the best Pin
Snyp17-Sep-03 11:06
Snyp17-Sep-03 11:06 
GeneralRe: C# is the best Pin
Rickard Andersson2017-Sep-03 21:53
Rickard Andersson2017-Sep-03 21:53 
GeneralRe: C# is the best Pin
Snyp18-Sep-03 10:46
Snyp18-Sep-03 10:46 

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.