473,473 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

validating an object pointer returned by an exported function

Hi,

I have a dll and one of its exported function is suppossed to return a
pointer to an object.
How can i check whether the exported function is of the same prototype
i want.
Please comment
Thanks & Regards
Srilal

Feb 22 '06 #1
8 1890
sr******@gmail.com wrote:
Hi,

I have a dll and one of its exported function is suppossed to return a
pointer to an object.
How can i check whether the exported function is of the same prototype
i want.


Please be noted that the concept of DLL may be implemented differently
across platforms and such a concept is not a concern of the C++ standard
and is generally off-topic in this newsgroup. You may therefore consult
platform specific documentation on DLL's or ask in a more suitable
newsgroup.

That said, I think the C++ name mangling would do the trick, although in
some systems it is mandated exported functions must be extern "C" and
therefore cannot be mangled.

Regards,
Ben

Feb 22 '06 #2
hi,
actually what i meant was, if i am executing the exported function
then how can i test if the returned values is a valid pointer to the
expected object.

Thanks & Regards,
Srilal

Feb 22 '06 #3
TB
sr******@gmail.com skrev:
hi,
actually what i meant was, if i am executing the exported function
then how can i test if the returned values is a valid pointer to the
expected object.

Thanks & Regards,
Srilal


If the function does not guarantee that a returned non-null pointer
is valid, then don't use the function.

--
TB @ SWEDEN
Feb 22 '06 #4
Hi,

here is the code snippent of my application

HINSTANCE hHandle = LoadLibrary ("UserDLL.dll");

//If the dll handle returns is null then trow exception.
if (!hHandle)
{ throw Exception; }

//Else get call the exported function pointer for creating the
object
typedef MyClass* (*pMyClass) ();

pMyClass pMyClassCreate= (pMyClass) GetProcAddress(hHandle,
"ExportedFunction");

if (!pMyClassCreate)
{
if (hHandle)
{
FreeLibrary (hHandle);
}

throw Exception
}

MyClass * pMyClassobj;
try
{
pMyClassobj = pMyClassCreate();
}
catch(...)
{
throw Exception;
}

try
{
pMyClass->MyFunction();
}
catch(...)
{
}

now my question is what if the ExportedFunction does not return the
pointer to MyClass
then executing pMyClass->MyFunction is giving access violations.

Thanks & Regards,
Srilal

Feb 22 '06 #5
TB
sr******@gmail.com skrev:
Hi,

here is the code snippent of my application

HINSTANCE hHandle = LoadLibrary ("UserDLL.dll");

//If the dll handle returns is null then trow exception.
if (!hHandle)
{ throw Exception; }

//Else get call the exported function pointer for creating the
object
typedef MyClass* (*pMyClass) ();

pMyClass pMyClassCreate= (pMyClass) GetProcAddress(hHandle,
"ExportedFunction");

if (!pMyClassCreate)
{
if (hHandle)
{
FreeLibrary (hHandle);
}

throw Exception
}

MyClass * pMyClassobj;
try
{
pMyClassobj = pMyClassCreate();
}
catch(...)
{
throw Exception;
}

try
{
pMyClass->MyFunction();
}
catch(...)
{
}

now my question is what if the ExportedFunction does not return the
pointer to MyClass
then executing pMyClass->MyFunction is giving access violations.


if(pMyClassobj) {
pMyClassobj->MyFunction();
}

--
TB @ SWEDEN
Feb 22 '06 #6
hi,

ok.
for me when i execute pMyClassCreate();
i get an invalid pointer to MyClass object ie. pobjMyClassobj is
invalid.

e.g if the ExportedFunction has the prototype int Function(int,int)
then executing it will give me int instead of MyClass*

so is there a way to check whether the returned pointer is of a valid
object because else executing MyFunction will give access violation.

Thanks & Regards,
Srilal

TB wrote:
sr******@gmail.com skrev:
Hi,

here is the code snippent of my application

HINSTANCE hHandle = LoadLibrary ("UserDLL.dll");

//If the dll handle returns is null then trow exception.
if (!hHandle)
{ throw Exception; }

//Else get call the exported function pointer for creating the
object
typedef MyClass* (*pMyClass) ();

pMyClass pMyClassCreate= (pMyClass) GetProcAddress(hHandle,
"ExportedFunction");

if (!pMyClassCreate)
{
if (hHandle)
{
FreeLibrary (hHandle);
}

throw Exception
}

MyClass * pMyClassobj;
try
{
pMyClassobj = pMyClassCreate();
}
catch(...)
{
throw Exception;
}

try
{
pMyClass->MyFunction();
}
catch(...)
{
}

now my question is what if the ExportedFunction does not return the
pointer to MyClass
then executing pMyClass->MyFunction is giving access violations.


if(pMyClassobj) {
pMyClassobj->MyFunction();
}

--
TB @ SWEDEN


Feb 22 '06 #7
TB
sr******@gmail.com skrev:
hi,

ok.
for me when i execute pMyClassCreate();
i get an invalid pointer to MyClass object ie. pobjMyClassobj is
invalid.
pobjMyClassobj? Can't find that name in the source code you posted.

e.g if the ExportedFunction has the prototype int Function(int,int)
then executing it will give me int instead of MyClass*
Yes, of course it does.

so is there a way to check whether the returned pointer is of a valid
object because else executing MyFunction will give access violation.

Which pointer, it apparently returns an 'int', not a pointer
to an object of MyClass.

int != MyClass*
Thanks & Regards,
Srilal

TB wrote:
sr******@gmail.com skrev:
Hi,

here is the code snippent of my application

HINSTANCE hHandle = LoadLibrary ("UserDLL.dll");

//If the dll handle returns is null then trow exception.
if (!hHandle)
{ throw Exception; }

//Else get call the exported function pointer for creating the
object
typedef MyClass* (*pMyClass) ();

pMyClass pMyClassCreate= (pMyClass) GetProcAddress(hHandle,
"ExportedFunction");

if (!pMyClassCreate)
{
if (hHandle)
{
FreeLibrary (hHandle);
}

throw Exception
}

MyClass * pMyClassobj;
try
{
pMyClassobj = pMyClassCreate();
}
catch(...)
{
throw Exception;
}

try
{
pMyClass->MyFunction();
}
catch(...)
{
}

now my question is what if the ExportedFunction does not return the
pointer to MyClass
then executing pMyClass->MyFunction is giving access violations.

if(pMyClassobj) {
pMyClassobj->MyFunction();
}

--
TB @ SWEDEN


--
TB @ SWEDEN
Feb 22 '06 #8
sr******@gmail.com wrote:
hi,

ok.
for me when i execute pMyClassCreate();
i get an invalid pointer to MyClass object ie. pobjMyClassobj is
invalid.

e.g if the ExportedFunction has the prototype int Function(int,int)
then executing it will give me int instead of MyClass*

so is there a way to check whether the returned pointer is of a valid
object because else executing MyFunction will give access violation.


I would simply do that like you do it with every other library function.
Make a header that belongs to the library and declare the prototype in that
header.

Feb 22 '06 #9

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

Similar topics

7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
1
by: Lloyd Dupont | last post by:
I have some managed C++ interacting with native DLL, for good integration I'm setting up some function pointer in the native DLL, passing some function pointer from the managed world....
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
7
by: Arpan | last post by:
The .NET Framework 2.0 documentation states that An Object variable always holds a pointer to the data, never the data itself. Now w.r.t. the following ASP.NET code snippet, can someone please...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
0
by: Stodge | last post by:
Hi folks, new to Boost Python and struggling to build a prototype at work. I thought I'd start with a conceptual question to help clarify my understanding. I already have a basic prototype working...
3
by: Giovanni Gherdovich | last post by:
Hello, in the following code I have a pointer (to function), say p, of type double (*)(double, double, void*) and I try to fix the second argument of the function *p to a given value (using...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
1
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
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...
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,...
1
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.