473,698 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LPSTR -> String : Type Incompatibility Issue

Another same issue on "NullReferenceE xception" :-
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
"NullReferenceE xception: 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.d ll" _
(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 1766
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.c om.my> wrote in message
news:Og******** ******@tk2msftn gp13.phx.gbl...
Another same issue on "NullReferenceE xception" :-
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
"NullReferenceE xception: 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.d ll" _
(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.c om.my> wrote in message
news:Og******** ******@tk2msftn gp13.phx.gbl...
Another same issue on "NullReferenceE xception" :-
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
"NullReferenceE xception: 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.d ll" _
(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
18586
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, how to write one? Thanks. --
1
2959
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 image, but when I change its color bits, say from 32bits to 24 or 16bits, the program can capture the image. Can anyone kindly examine my following code, and point out the flaw:
4
4884
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 necessarily environment specific. I have written a VB program that passes an array of strings to a C++ dll. The c++ dll is supposed to fill the array of strings with the appropriate value. The only way i figured out how to pass was it by reference....
4
1685
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 thread. so, next time when thread runs, whole block is allocated for the second time and in just 10 tries, my PC got hang because of memory problem. I know GlobalFree(HGLOBAL) function and already used it but in vain.. So, is there any function that...
0
2263
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 buffer is not marked as done until it's full. The documentation says that calling the sequence WaveinStop(HWAVEIN) we stop recording marking a buffer as done, end the member dwbyterecorded contains the amount of data. why calling WaveInstop...
2
3124
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 use cmdLineParameter in other functions. If any body knows pls help me I am trying the following code sample: char **cmdLineParameter;
7
3477
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 szResult) { char resultchar; //some processing which put the result values in resultchar strcpy(szResult, &resultchar); return 0;
8
2825
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 program to extract the substring, but something wrong char* deangle(const char* lpStr)
3
4627
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++ version connect to the DDE server somehow -- DdeConnect(idInst,hszService, hszTopic, NULL) is not working I am not sure if it's because DDEML doesn't support the connection, or if it's because my code is incorrect (I'm not familiar with VB, so I'm...
9
36508
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 pString ) { if(pString)
0
8675
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7729
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6521
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4370
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.