Advertisement

05.02.2006 at 02:59PM PDT, ID: 21835580
[x]
Attachment Details

Interfacing C# and C Dll Files using pointers that are sometimes required null with const TCHAR*   500pts

Asked by wibuus in Miscellaneous Programming

Tags: dll

I have a C dll that I am writing a .NET wrapper for. Other functions that don't involve string-like types work. If i try to pass it as a string back to the C dll, then it gives me a Stack Imbalance error. Same goes for uint, IntPtr, and char[]. Anyway, Here is the function declaration in the API manual:
HENTRY Open2(const TCHAR *pszPort)

And here is my DllImport & function (APILIB is a constant declared earlier)
[DllImport(APILIB, PreserveSig = true)]
private static extern HWKBENTRY Open2(ref char pszPort);

public static HWKBENTRY WkbOpen(string pszPort)
{
            //translate
            byte[] arg2 = System.Text.Encoding.Default.GetBytes(pszPort);
            return Open2(ref arg2[0]);
}
This works... except for one problem. I need to be able to pass a null pointer. Passing a null does not work. Passing a ref to a 0 byte does not work. I'm pretty lost on this one,
Thanks
ChrisStart Free Trial
 
Loading Advertisement...
 
[+][-]05.03.2006 at 06:10AM PDT, ID: 16595760

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Miscellaneous Programming
Tags: dll
Sign Up Now!
Solution Provided By: Daeljan
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.03.2006 at 06:19AM PDT, ID: 16595855

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.03.2006 at 08:28AM PDT, ID: 16597133

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.03.2006 at 09:41AM PDT, ID: 16597852

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32