473,508 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LPSTR -> String : Type Incompatibility Issue

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.

Nov 17 '05 #1
2 1753
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


"Michael Chong" <mi*****@cyob.com.my> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
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.

Nov 17 '05 #2
> "Michael Chong" <mi*****@cyob.com.my> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
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,

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
Nov 17 '05 #3

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

Similar topics

14
18565
by: Siemel Naran | last post by:
There is a function stricmp that compares two strings without case sensitivity. We have strstr that searches for a substring, taking case into account. Is there a function stristr? If not,...
1
2948
by: xc | last post by:
Greetings. I encountered a wield problem when grabing screen images. Sometimes in some computers I can capture the screen, but other times not so. In some computer I cannot capture the screen...
4
4872
by: Gent | last post by:
Below is a straightforward C++ question but i'm giving example code to demonstrate the issue i'm having. THe issue might seem to be out of the topic but it's mostly related to C++ and is not...
4
1672
by: Jigar Mehta | last post by:
Hye, I am using one object which allocates around 2 MB of memory.. Now after use, I want it to free. But the task can not be done. the memory is still allocated and not freed. I am using it in...
0
2240
by: Diego | last post by:
Hello. I need help. I'm writing an application that requires audio recording and I have decided to use waveform audio interface. I'm able to process WIM_DATA message but when i call waveInStop the...
2
3117
by: Nagesh | last post by:
hi, I am want copy the command line arguments from szCmdLine of WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) into **char cmdLineParameter. So that I can...
7
3456
by: Asfar | last post by:
I have a MFC dll in which one of the parameters is of LPSTR. The declaration of my MFC dll looks like extern "C" __declspec(dllexport) int WINAPI EXPORT TestPInvokeFunc(LPSTR szFileName, LPSTR...
8
2806
by: gmclee | last post by:
Hi there, I need a program to extract a substring from the following pattern xxxx<XXXXX>xxxx therer, x and X are any character and the string between < and is what I need. I use the following...
3
4616
by: =?Utf-8?B?Q2luZHk=?= | last post by:
Hi all, I am trying to connect to a electromyograph machine for my thesis project, and I have a VB DDE client whose DDE functionality I want to convert to VC++. However I can't make my VC++...
9
36393
by: X Enterprises | last post by:
Hello :) I'm not new to C++, I just don't use it as much as I used to. But anyway, I need to convert LPSTR to LPCWSTR. Here's the function i'm using it in: MYCOMMAND void PrintText( LPSTR...
0
7233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7135
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
7410
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...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.