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

C#

 
GeneralRe: Linking 3 tables to 1 form Pin
Daniel.J.A28-Sep-09 12:14
Daniel.J.A28-Sep-09 12:14 
GeneralRe: Linking 3 tables to 1 form Pin
Henry Minute28-Sep-09 12:25
Henry Minute28-Sep-09 12:25 
Questionhow to mark some rows in datagrid ? Pin
E_Gold28-Sep-09 9:37
E_Gold28-Sep-09 9:37 
AnswerRe: how to mark some rows in datagrid ? Pin
Henry Minute28-Sep-09 10:17
Henry Minute28-Sep-09 10:17 
QuestionDoes anyone know of an recommending tool... Pin
Paw Jershauge28-Sep-09 8:31
Paw Jershauge28-Sep-09 8:31 
AnswerRe: Does anyone know of an recommending tool... Pin
Henry Minute28-Sep-09 9:20
Henry Minute28-Sep-09 9:20 
GeneralRe: Does anyone know of an recommending tool... Pin
Paw Jershauge28-Sep-09 22:01
Paw Jershauge28-Sep-09 22:01 
QuestionMarshaling between managed and unmanaged [modified] Pin
akhanal28-Sep-09 6:47
akhanal28-Sep-09 6:47 
I have an unmanaged function with a signature as follows:

func1(unsigned __int16 arg1, unsigned __int16 arg2, unsigned __int16** arg3);

now this is being called in the correctly working unmanaged code as:

{
unsigned __int16 arg1;
unsigned __int16 arg2;
unsigned __int16* arg3;
unsigned int test;
....
test = func1(arg1, arg2, &arg3));

.........
.........
}


I have imported the function(func1()) in the managed c# code as:

[DllImport("SomeDLL.dll", EntryPoint = "func1")]
unsafe public static extern uint func1(UInt32 arg1, UInt32 arg2, out UInt32* arg3);

And I am calling this function in my code as:

{
........
UInt32 arg1;
UInt32 arg2;
UInt32* arg3;
uint test;

...........
test = func1(arg1, arg2, out arg3);

............
/* I am using arg3 value over here*/
if(arg3[0] == null)
{
....
}
}

Now my problem is, in the unmanaged code when I access the arg3[0], it gives me a value, but in the managed code it gives me a pointer, to elaborate:

When I watch arg3 in the watch window in unmanaged code it shows as an array with the arg3 as a pointer and its 0 index value just as a value:

Name Value
- arg3 0x0F031321
arg3 1

in managed code it is:

Name Value
- arg3 0x000000000F031321
*arg3 490799104

notice that in the drop down list above the unmanaged code simply has arg3 in the second line whereas the managed code has *arg3. So my guess is in the latter the first value of the array is a pointer.

Even when I import the function as:

[DllImport("SomeDLL.dll", EntryPoint = "func1")]
unsafe public static extern uint func1(UInt32 arg1, UInt32 arg2, UInt32** arg3);

and call it as:

{
........
UInt32 arg1;
UInt32 arg2;
UInt32* arg3;
uint test;

...........
test = func1(arg1, arg2, &arg3);

............
}

Again, I have the same problem in the managed code.

Can someone please point the errors in my marshaling, and suggest some solutions.
Appreciate all the help.

modified on Monday, September 28, 2009 4:06 PM

AnswerRe: Marshaling between managed and unmanaged Pin
Luc Pattyn28-Sep-09 7:45
sitebuilderLuc Pattyn28-Sep-09 7:45 
GeneralRe: Marshaling between managed and unmanaged Pin
akhanal28-Sep-09 8:28
akhanal28-Sep-09 8:28 
GeneralRe: Marshaling between managed and unmanaged Pin
Luc Pattyn28-Sep-09 8:48
sitebuilderLuc Pattyn28-Sep-09 8:48 
GeneralRe: Marshaling between managed and unmanaged Pin
Richard MacCutchan28-Sep-09 9:16
mveRichard MacCutchan28-Sep-09 9:16 
GeneralRe: Marshaling between managed and unmanaged Pin
Luc Pattyn28-Sep-09 9:32
sitebuilderLuc Pattyn28-Sep-09 9:32 
GeneralRe: Marshaling between managed and unmanaged [modified] Pin
akhanal28-Sep-09 9:28
akhanal28-Sep-09 9:28 
GeneralRe: Marshaling between managed and unmanaged [modified] Pin
Luc Pattyn28-Sep-09 9:43
sitebuilderLuc Pattyn28-Sep-09 9:43 
GeneralRe: Marshaling between managed and unmanaged [modified] Pin
akhanal28-Sep-09 10:06
akhanal28-Sep-09 10:06 
GeneralRe: Marshaling between managed and unmanaged Pin
Luc Pattyn28-Sep-09 10:45
sitebuilderLuc Pattyn28-Sep-09 10:45 
GeneralRe: Marshaling between managed and unmanaged Pin
akhanal28-Sep-09 11:03
akhanal28-Sep-09 11:03 
GeneralRe: Marshaling between managed and unmanaged Pin
akhanal28-Sep-09 12:01
akhanal28-Sep-09 12:01 
GeneralRe: Marshaling between managed and unmanaged Pin
Luc Pattyn28-Sep-09 12:18
sitebuilderLuc Pattyn28-Sep-09 12:18 
GeneralRe: Marshaling between managed and unmanaged Pin
akhanal29-Sep-09 4:04
akhanal29-Sep-09 4:04 
GeneralRe: Marshaling between managed and unmanaged Pin
Luc Pattyn29-Sep-09 4:17
sitebuilderLuc Pattyn29-Sep-09 4:17 
GeneralRe: Marshaling between managed and unmanaged [modified] Pin
akhanal29-Sep-09 5:02
akhanal29-Sep-09 5:02 
GeneralRe: Marshaling between managed and unmanaged Pin
Luc Pattyn29-Sep-09 5:36
sitebuilderLuc Pattyn29-Sep-09 5:36 
GeneralRe: Marshaling between managed and unmanaged Pin
akhanal29-Sep-09 5:32
akhanal29-Sep-09 5:32 

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.