Hello,
Is it possible to instantiate and use a c++ class from within a DLL?
I ask this, because I attempted to create a class within a DLL, and
export its methods via wrapper C functions, and although it all
compiles find, it returns garbage. The following is only test code to
see what I can do. I want to eventually make this functionality
available to a Visual Basic program, which keeps me from exporting a
class directly (I assume VB can't use classes).
In pure C code, this works, but somehow I can't make a class work.
//In the DLL I have two files GamePad.h and GamePad.cpp:
******First GamePad.h:
class CGamePad {
int i;
public:
GamePad() { i = 15;}
void inc(){ i++;}
void dec(){ i--;}
int get(){return i;}
void set(int _i){ i = _i;}
};
******Next GamePad.cpp
#include <windows.h>
#include <iostream>
#include "GamePad.h"
CGamePad *p_pad=0;
CGamePad g_oPad;
using namespace std;
#define DllExport extern "C" __declspec (dllexport)
DllExport void inc()
{
g_oPad.inc();
}
DllExport void dec()
{
g_oPad.dec();
}
DllExport int get()
{
i = g_oPad.get();
return i;
}
DllExport void set(int i)
{
g_oPad.set(i);
}
I call and use these functions in my C++ program, by linking in the
DLL, and the functions return garbage.
What is the reason for this, and is there a way I can employ C++
classes within a DLL, and export them through C functions?
Thanks for any feedback!
....John 4 1461
"John Alway" <jw*****@hotmai l.com> ????
news:db******** *************** ***@posting.goo gle.com... Hello,
Is it possible to instantiate and use a c++ class from within a DLL?
I ask this, because I attempted to create a class within a DLL, and export its methods via wrapper C functions, and although it all compiles find, it returns garbage. The following is only test code to see what I can do. I want to eventually make this functionality available to a Visual Basic program, which keeps me from exporting a class directly (I assume VB can't use classes).
In pure C code, this works, but somehow I can't make a class work.
//In the DLL I have two files GamePad.h and GamePad.cpp:
******First GamePad.h:
// just use
class __declspec(dlle xport) CGamePad{
// member functions and data members
} ;
// but it cann't be dynamic load, eg you can't use loadlibrary() function to
load the dll, just staticly load the library in your program
class CGamePad { int i; public: GamePad() { i = 15;} void inc(){ i++;} void dec(){ i--;} int get(){return i;} void set(int _i){ i = _i;} };
******Next GamePad.cpp
#include <windows.h> #include <iostream> #include "GamePad.h" CGamePad *p_pad=0; CGamePad g_oPad;
using namespace std;
#define DllExport extern "C" __declspec (dllexport) DllExport void inc() { g_oPad.inc();
}
DllExport void dec() { g_oPad.dec();
}
DllExport int get() { i = g_oPad.get(); return i; }
DllExport void set(int i) { g_oPad.set(i); }
I call and use these functions in my C++ program, by linking in the DLL, and the functions return garbage.
What is the reason for this, and is there a way I can employ C++ classes within a DLL, and export them through C functions?
Thanks for any feedback!
...John
"John Alway" <jw*****@hotmai l.com> wrote in message
news:db******** *************** ***@posting.goo gle.com... Hello,
Is it possible to instantiate and use a c++ class from within a DLL?
This is a platform specific question, and therefore off topic on this group,
which deals with standard C++ only. Suggest you try
news:comp.os.ms-windows.program mer.win32.
It clearly is possible because I was reviewing some code just the other day
that did exactly that. But for the details you should ask on a platform or
compiler specific group.
john
"John Alway" <jw*****@hotmai l.com> wrote in message
news:db******** *************** ***@posting.goo gle.com... Is it possible to instantiate and use a c++ class from within a DLL?
Yes -- but note that DLLs are platform-specific and
outside the scope of this NG.
I call and use these functions in my C++ program, by linking in the DLL, and the functions return garbage.
What is the reason for this, and is there a way I can employ C++ classes within a DLL, and export them through C functions?
I happen use similar techniques, and it works well for me.
To locate the cause of the problem you encounter, more information
is needed about the "garbage" you are seeing.
Could it be that the problem is only that the constructor of
your global C++ variable is not called?
If you call the "set" function, what happens then?
Did you insert some logging (e.g. DebugString) calls to
verify that your functions are actually called?
Once you have investigated this, I would suggest re-posting
your question, if needed, on a platform-specific forum.
Such as microsoft.publi c.vc.language
hth -Ivan
-- http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
"Ivan Vecerina" <IN************ *************** **@vecerina.com > wrote in message news:<ck******* **@newshispeed. ch>... "John Alway" <jw*****@hotmai l.com> wrote in message news:db******** *************** ***@posting.goo gle.com... Is it possible to instantiate and use a c++ class from within a DLL? Yes -- but note that DLLs are platform-specific and outside the scope of this NG. I call and use these functions in my C++ program, by linking in the DLL, and the functions return garbage.
What is the reason for this, and is there a way I can employ C++ classes within a DLL, and export them through C functions?
I happen use similar techniques, and it works well for me.
To locate the cause of the problem you encounter, more information is needed about the "garbage" you are seeing. Could it be that the problem is only that the constructor of your global C++ variable is not called?
Bingo! I'm embarrassed to say it was a typo! My constructor
should be CGamePad(), not GamePad(). So, it works.
Thanks much!
If you call the "set" function, what happens then? Did you insert some logging (e.g. DebugString) calls to verify that your functions are actually called?
Once you have investigated this, I would suggest re-posting your question, if needed, on a platform-specific forum. Such as microsoft.publi c.vc.language
Will do.
Regards,
...John This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mehrdad |
last post by:
Hello,
I have a set of C# classes and I am trying to instanciate and call them in a
managed C++ project. I have been searching a lot but so far could not find
any example or document on how to this. I have heard people say it is even
possible to wirte a class in C# and subclass it in C++. Can anybody give me a
hint or some link to related usefull documents.
thanks.
|
by: Geoff Jones |
last post by:
Hi
I'm starting to look at C# after programming in C++ and was wondering if
anybody could help me with the following questions:
(1) What is the difference between a Project and Solution In Visual Studio
..NET?
(2) When programming in C++, to allow a file/class to know about other
classes, I normally include a header file in the source file of the class.
|
by: joye |
last post by:
Hello,
My question is how to use C# to call the existing libraries containing
unmanaged C++ classes directly, but not use C# or managed C++ wrappers
unmanaged C++ classes?
Does anyone know how to do that?
Thanks.
Tsung-Yu
|
by: Mark |
last post by:
I have it in my head that I saw a marketing document from Microsoft with the
total number of classes and methods in the .NET Framework. Something like
70,000 methods? I don't need precise numbers, but a rough estimate of the
number of classes and methods would be useful ....
Thanks in advance.
Mark
|
by: MIGUEL |
last post by:
Hi all,
I'm quite lost with how adding web references to a project creates proxy
classes.
I've developed a web service with two classes inside and that contains three
references to three DLLs. After building it up, I've deployed it on the web
server.
From my Windows application, I then add a web reference to that web service.
| |
by: Brian Bischof |
last post by:
I'm having troubles getting the debugging process to work consistenly for
external classes. I got it to work once and then I turned it off. But now I
can't get re-enabled. Here is what I'm doing. If someone could tell me what
I'm missing that would be great.
1. Create an external class and call it Test.dll.
2. Create a test Asp.net app called App.sln.
3. For App.sln I set a reference to Test.dll.
4. Compile App.sln and run it. The web...
|
by: Oenone |
last post by:
I've been working on migration of my company's VB6 ASP system to VB2005 over
the last year or so, and am currently presenting my findings and recommended
course of action to our management team. One of the concerns that has been
raised is with regard to the .dll files that form our service being placed
into a directory within the publically available web site (i.e., the bin
directory).
We have long held the view that private files...
|
by: jason |
last post by:
Please pardon my completely lack of understanding on the topic.
I have a website I developed with another developer. We are both far
from experts in VB.NET and OOP. We developed the site WITHOUT VS.NET,
compiling vb.net code into a common dll in the bin directory off the
root of the website. That one vb code creates a namespace we import in
all of our ASP.NET code. Compiling was done fromt he command line use
vbc.exec.
The site works...
|
by: amitdedhia |
last post by:
Hi
I am migrating a product code (originally written in VS2003) to VS2005.
The application is written in VC++ (using MFC) and has mix of managed
and unmanaged classes. It is a desktop based application which controls
an instrument (a device) and interacts with it.
I fixed all the compiler errors and ran the application. I got a
message that "The procedure entry point XXX could not be located in the
dynamic link library AAAA.dll.
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |