473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

exporting function with parm pointer to char string

I'm exporting a C-style function call with this syntax:

int getDate(char *date);

I'm trying to export to my c# app like this:

[DllImport("C:\\zm7\\Developm\\DLL\\W32.DLL")]
public static extern int getDate(System.IntPtr ptr);
public void getDate()
{
IntPtr ptr = new IntPtr();
string str = "";
getDate(ptr); //// ERROR: Object reference not set to an instance of
an object
str = Marshal.PtrToStringAnsi(ptr);
}

What Am I doing wrong?

Thanks.
Nov 15 '05 #1
2 1648
>What Am I doing wrong?

You're passing in a null pointer. Try it this instead

public static extern int getDate(StringBuilder ptr);

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2
That worked.

Thank you.

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:uj**************@TK2MSFTNGP10.phx.gbl...
What Am I doing wrong?


You're passing in a null pointer. Try it this instead

public static extern int getDate(StringBuilder ptr);

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Angel | last post by:
I'm trying to call a DLL function that receives as parameter a user-defined structure created by the company that made the dll. When I call the function from my main form, I call...
6
by: Angel | last post by:
I'm exporting (with DllImport) a C-style function with this syntax: int z9indqry (4_PARM *parm); 4_PARM is a structure declared in a proprietary header file that cannot be included in my...
6
by: yamu_rhyme | last post by:
Is there any split function in DB2? How to split a field value separated with delimiter ","(comma)?
20
by: Bruce. | last post by:
I am trying to call a member function through a pointer to it and can't get the syntax exactly right. This compiles with an error C2064, term does not evaluate to a function taking 1 argument.. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.