473,395 Members | 2,423 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,395 software developers and data experts.

'HANDLE *' Error

I am using a DLL function (complied in VC7), which takes a parameter
of 'HANDLE *' datatype.
The DLL developers recommend passing a HANDLE object using the
following syntax:

HANDLE obj =NULL;
func(&obj);

On successful execution of the code 'obj' is initialised to some
value.

This code works if used within VC++ MFC Application using VS2005.
But the same doesnt work in VC++ Windows Form Application using
VS2005.

In a VC++ Windows Form Application using VS2005, the compiler expects
the following syntax:

HANDLE obj =NULL;
func((HANDLE *)obj);

This compiles but gives a runtime error, and fails to initialise
'obj'.

What am I doing wrong? And how can I use the DLL function in a VC++
Windows Form Application using VS2005.

Thanks,
Bhumi

Oct 15 '07 #1
3 1335
You are passing a null address to the function, and the function expects a
valida address to write to. You can use new to allocate memory on the native
heap, pass it to the dll to retrieve the new handle, and copy the handle
value to the managed heap.

--
Sheng Jiang
Microsoft MVP in VC++
<bh**********@gmail.comwrote in message
news:11*********************@z24g2000prh.googlegro ups.com...
I am using a DLL function (complied in VC7), which takes a parameter
of 'HANDLE *' datatype.
The DLL developers recommend passing a HANDLE object using the
following syntax:

HANDLE obj =NULL;
func(&obj);

On successful execution of the code 'obj' is initialised to some
value.

This code works if used within VC++ MFC Application using VS2005.
But the same doesnt work in VC++ Windows Form Application using
VS2005.

In a VC++ Windows Form Application using VS2005, the compiler expects
the following syntax:

HANDLE obj =NULL;
func((HANDLE *)obj);

This compiles but gives a runtime error, and fails to initialise
'obj'.

What am I doing wrong? And how can I use the DLL function in a VC++
Windows Form Application using VS2005.

Thanks,
Bhumi

Oct 15 '07 #2
On Oct 16, 1:00 am, "Sheng Jiang[MVP]"
<sheng_ji...@hotmail.com.discusswrote:
You are passing a null address to the function, and the function expects a
valida address to write to. You can use new to allocate memory on the native
heap, pass it to the dll to retrieve the new handle, and copy the handle
value to the managed heap.

--
Sheng Jiang
Microsoft MVP in VC++<bhumithak...@gmail.comwrote in message

news:11*********************@z24g2000prh.googlegro ups.com...
I am using a DLL function (complied in VC7), which takes a parameter
of 'HANDLE *' datatype.
The DLL developers recommend passing a HANDLE object using the
following syntax:
HANDLE obj =NULL;
func(&obj);
On successful execution of the code 'obj' is initialised to some
value.
This code works if used within VC++ MFC Application using VS2005.
But the same doesnt work in VC++ Windows Form Application using
VS2005.
In a VC++ Windows Form Application using VS2005, the compiler expects
the following syntax:
HANDLE obj =NULL;
func((HANDLE *)obj);
This compiles but gives a runtime error, and fails to initialise
'obj'.
What am I doing wrong? And how can I use the DLL function in a VC++
Windows Form Application using VS2005.
Thanks,
Bhumi- Hide quoted text -

- Show quoted text -
Thanks Sheng. Got it to work now.

Thanks,
Bhumi

Oct 16 '07 #3

<bh**********@gmail.comwrote in message
news:11*********************@z24g2000prh.googlegro ups.com...
>I am using a DLL function (complied in VC7), which takes a parameter
of 'HANDLE *' datatype.
The DLL developers recommend passing a HANDLE object using the
following syntax:

HANDLE obj =NULL;
func(&obj);

On successful execution of the code 'obj' is initialised to some
value.

This code works if used within VC++ MFC Application using VS2005.
But the same doesnt work in VC++ Windows Form Application using
VS2005.
It should, because that is the correct version.

>
In a VC++ Windows Form Application using VS2005, the compiler expects
the following syntax:

HANDLE obj =NULL;
func((HANDLE *)obj);

This compiles but gives a runtime error, and fails to initialise
'obj'.

What am I doing wrong? And how can I use the DLL function in a VC++
Windows Form Application using VS2005.

Thanks,
Bhumi

Oct 16 '07 #4

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

Similar topics

7
by: Tony Johansson | last post by:
Hello!! Assume I have a handle body pattern with classes called Handle and Body. In the Body class I store one int value for example 7 or some other integer value. In the Handle class I have...
0
by: nek | last post by:
Would anyone have any ideas or come across the 'invalid handle' problem? Even after setting diaglevel=4, I could not get much out of the db2diag.log to diagnose the problem. The only thing I...
14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
6
by: Leandro Berti via DotNetMonster.com | last post by:
Hi All, I wrote a code to do serial communication with an equipament. When i use the code outside of threaded class it seens work properly, but when i put inside a class and execute a thread in...
6
by: Mark | last post by:
Hello, I'm trying to handle HttpRequestValidationException. If a hacker enters certain values into a textbox, like "<script>", it will trigger this error. I understand why .Net has this, but I...
3
by: clintonb | last post by:
Some programmers, and even Microsoft documents, say you should only throw exceptions for exceptional situations. So how are others handling all the other unexceptional errors? How are you...
6
by: Liming | last post by:
Hi, In a typical 3 tier model (view layer, busines layer and data access layer) where do you handle your exceptions? do you let it buble up all the way to the .aspx pages or do you handle it in...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
3
by: Peterwkc | last post by:
Hello all C++ expert programmer, I have a handle class which point to another class and use the pointer as object. I follow the code from C++ articles submited by someone in this forum....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
0
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...
0
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,...

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.