Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / September 2004

Tip: Looking for answers? Try searching our database.

LPSTR -> String : Type Incompatibility Issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Chong - 15 Sep 2004 06:11 GMT
Another same issue on "NullReferenceException" :-
I have an (exe) executable program created in VB.NET 2003 that calls to a
MFC DLL written in VC++.NET 2003. I always get an error msg
"NullReferenceException: Object Reference Not Set to an Instance of an
Object" when my exe calls the following codes:

in VB.NET

   Declare Function test Lib "C:\Cyob\IOComm\Debug\IOComm.dll" _
   (ByVal a As Long, ByRef b As String) As Integer

    Dim did As Integer
    Dim ret As Integer

    ret = test(PortHnd, did)     //ERROR: Object Reference Not Set to an
Instance of an Object

in VC++.NET

extern "C" int APIENTRY test(HANDLE a, LPSTR b)
{
    strcpy(b, "hello");         //ERROR: Object Reference Not Set to an
Instance of an Object
    return 99;
}

Why is this happening? Any idea in solving such matter?
Thanks in Advance

Michael.
Michael Chong - 15 Sep 2004 06:19 GMT
Sorry, the "Dim did as Integer" should be "Dim did as String"
I believe is DataType issue from VC++.NET (LPSTR) pass to VB.NET (String)

When I try to replace String with IntPtr, it doesn't give me error but the
return value for "did variable" is some numbers.
Plz help! TQ

> Another same issue on "NullReferenceException" :-
> I have an (exe) executable program created in VB.NET 2003 that calls to a
[quoted text clipped - 26 lines]
>
> Michael.
Wild Wind - 18 Sep 2004 13:39 GMT
>> Another same issue on "NullReferenceException" :-
>> I have an (exe) executable program created in VB.NET 2003 that calls
[quoted text clipped - 26 lines]
>>
>> Michael.

Michael,

It looks like you haven't allocated memory to copy the
"hello" to in your strcpy call.

Try putting

b = new CHAR[strlen("hello") + 1];

before your call to strcpy.

--
Akin

aknak at aksoto dot idps dot co dot uk

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.