473,386 Members | 1,754 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,386 software developers and data experts.

Function pointers and dynamically loaded DLLs

In my program, I load dynamically a DLL and I'm able to get a function
pointer of type "int (__cdecl *)(void)" of any function in the DLL.

If a DLL has a static class function, which calls the constructor and
returns a pointer to the constructed instance of the class, then I don't
have any problems.

However, if a DLL doesn't have such static function, then I can't get it
working. I'm able to get a function pointer to the class constructor,
but I have no idea how to call the constructor in the way that that it
also creates instance of the class (with 'operator new' obviously).
Calling just the constructor, of course, doesn't return a valid instance
of the class.

The header of the DLL is basically like this:
class dllclass
{
public:
__declspec(dllexport) virtual ~dllclass();
__declspec(dllexport) dllclass();

__declspec(dllexport) virtual void dosomething1();
__declspec(dllexport) virtual void dosomething2();
__declspec(dllexport) virtual void dosomething3();
};

I cannot change the DLL, so that kind of workaround isn't possible.

Any suggestions? Is it even possible? Thanks in advance.

Jul 23 '05 #1
1 2027
"Domer" <do***@domer.domer> wrote...
In my program, I load dynamically a DLL and I'm able to get a function
pointer of type "int (__cdecl *)(void)" of any function in the DLL.

If a DLL has a static class function, which calls the constructor and
returns a pointer to the constructed instance of the class, then I don't
have any problems.

However, if a DLL doesn't have such static function, then I can't get it
working. I'm able to get a function pointer to the class constructor, but
I have no idea how to call the constructor in the way that that it also
creates instance of the class (with 'operator new' obviously). Calling
just the constructor, of course, doesn't return a valid instance of the
class.

The header of the DLL is basically like this:
class dllclass
{
public:
__declspec(dllexport) virtual ~dllclass();
__declspec(dllexport) dllclass();

__declspec(dllexport) virtual void dosomething1();
__declspec(dllexport) virtual void dosomething2();
__declspec(dllexport) virtual void dosomething3();
};

I cannot change the DLL, so that kind of workaround isn't possible.

Any suggestions? Is it even possible? Thanks in advance.


It is possible. However, it's not Standard, it's not portable, and it is
all very compiler-specific. Please ask about this in a newsgroup dedicated
to your compiler. If this is VC++, try microsoft.public.vc.language. If
your ISP doesn't carry it, connect to 'msnews.microsoft.com', it's free.

V
Jul 23 '05 #2

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

Similar topics

0
by: Peter | last post by:
I use dynamically loaded dll's a lot in my programs. The one thing i cannot figure out how do is too to sucessfully pass the address of a class instance created within the dynamically loaded dll. ...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
9
by: Robby Bankston | last post by:
I'm working on some code and am running into brick walls. I'm trying to write out Javascript with Javascript and I've read the clj Meta FAQ and didn't see the answer, read many similar posts (with...
11
by: Marco Loskamp | last post by:
Dear list, I'm trying to dynamically generate functions; it seems that what I really want is beyond C itself, but I'd like to be confirmed here. In the minimal example below, I'd like to...
0
by: Konstantin Gonikman | last post by:
Hi, I just played around with WebResource and embeding .js and .css files into my dlls. All works perfectly except following: As I try to embed any WebResources in assemblies that are loaded...
6
by: Dan Dorey | last post by:
I actually have two questions here, but I'll start by giving an outline of what I'm trying to do. I'm building an app with a simple plugin architecture (all in the same app domain). I have each...
2
by: David McCallum | last post by:
I'm not infront of my computer just now, but I seem to remember when my app is being executed the output console shows all the DLLs being loaded. Is there anyway to load these DLLs as and when...
0
by: Markus Eßmayr | last post by:
Hello! I'm writing a .NET component that forwards calls to it's functions on to an unmanaged DLL. This DLL is loaded dynamically using LoadLibrary and the function pointers are retrieved using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
0
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
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...

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.