Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
GeneralRe: global settings Pin
Colin Angus Mackay7-Sep-06 9:29
Colin Angus Mackay7-Sep-06 9:29 
GeneralRe: global settings Pin
e_LA6-Sep-06 0:13
e_LA6-Sep-06 0:13 
GeneralRe: global settings Pin
Colin Angus Mackay7-Sep-06 9:32
Colin Angus Mackay7-Sep-06 9:32 
GeneralRe: global settings Pin
e_LA7-Sep-06 23:20
e_LA7-Sep-06 23:20 
QuestionHow I can get control's id property via api ? Pin
Marco22504-Sep-06 3:28
Marco22504-Sep-06 3:28 
Questionform showdialog problem ? help please ... Pin
cmpeng344-Sep-06 3:05
cmpeng344-Sep-06 3:05 
AnswerRe: form showdialog problem ? help please ... [modified] Pin
Martin#4-Sep-06 3:08
Martin#4-Sep-06 3:08 
QuestionC-C# Interop problem Pin
Utkarshraj Atmaram4-Sep-06 2:40
Utkarshraj Atmaram4-Sep-06 2:40 
I'm relatively new to C#, and just started with interop. I've a C DLL with this function:

int SomeFunction  (
	const int id,  
	const char *  name,
	int  num = 0,  
	CLASS1 *const ptr1 = NULL,  
	CLASS2 *const ptr2 = NULL
)


I wrote a C# file for this C library and defined this function as:

[DllImport(DLLNAME)]
public static extern int SomeFunction(
	int id,
	string name,
	SIPX_CONTACT_ID num,
	IntPtr ptr1,
	IntPtr ptr2
);


Now I've got only the values of only first three parameters. So, I want to pass the last two parameters as null. But I got "Cannot convert null to System.IntPtr because it is a value type" error.

To solve this problem I rewrote C# file as:

[DllImport(DLLNAME)]
public static extern int SomeFunction(
	int id,
	string name,
	SIPX_CONTACT_ID num,
	ref CLASS1 ptr1,
	ref CLASS2 ptr2
);


Is this correct? It's not giving me the desired results. SomeFunction is returning me
wrong values.

I also tried an alternative approach. In the C# file, I declared an overloaded
function as:

// simulating const function parameters using method overloading
[DllImport(DLLNAME)]
public static extern int SomeFunction(
	int id,
	string name
);


Then I called the function with only first two arguments. But that gives me an System.AccessViolationException: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

What's wrong with this code?

Ut

AnswerRe: C-C# Interop problem Pin
mikone4-Sep-06 3:21
mikone4-Sep-06 3:21 
GeneralRe: C-C# Interop problem Pin
Utkarshraj Atmaram4-Sep-06 3:31
Utkarshraj Atmaram4-Sep-06 3:31 
GeneralRe: C-C# Interop problem Pin
Utkarshraj Atmaram7-Sep-06 3:26
Utkarshraj Atmaram7-Sep-06 3:26 
QuestionHow to save my picture? Pin
txwd4-Sep-06 2:10
txwd4-Sep-06 2:10 
AnswerRe: How to save my picture? Pin
Jakub Mller4-Sep-06 4:57
Jakub Mller4-Sep-06 4:57 
Questioninterface vs abstract class Pin
psamy4-Sep-06 1:41
psamy4-Sep-06 1:41 
AnswerRe: interface vs abstract class Pin
Jonathan van de Veen4-Sep-06 1:48
Jonathan van de Veen4-Sep-06 1:48 
AnswerRe: interface vs abstract class Pin
SeMartens4-Sep-06 1:49
SeMartens4-Sep-06 1:49 
Questionhow to deploy a vsto solution to portal doc library Pin
jacktom4-Sep-06 1:24
jacktom4-Sep-06 1:24 
AnswerRe: how to deploy a vsto solution to portal doc library Pin
WillemM4-Sep-06 5:20
WillemM4-Sep-06 5:20 
GeneralRe: how to deploy a vsto solution to portal doc library Pin
jacktom4-Sep-06 16:21
jacktom4-Sep-06 16:21 
GeneralRe: how to deploy a vsto solution to portal doc library Pin
jacktom5-Sep-06 20:44
jacktom5-Sep-06 20:44 
Questiongif image Pin
TAREQ F ABUZUHRI4-Sep-06 1:21
TAREQ F ABUZUHRI4-Sep-06 1:21 
AnswerRe: gif image Pin
TAREQ F ABUZUHRI4-Sep-06 1:21
TAREQ F ABUZUHRI4-Sep-06 1:21 
GeneralRe: gif image Pin
SeMartens4-Sep-06 1:34
SeMartens4-Sep-06 1:34 
QuestionSQLClient has cross object code? Pin
Jonathan van de Veen4-Sep-06 0:53
Jonathan van de Veen4-Sep-06 0:53 
AnswerRe: SQLClient has cross object code? Pin
Colin Angus Mackay4-Sep-06 1:06
Colin Angus Mackay4-Sep-06 1:06 

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.