|
I have a DLL where I'm exporting a class...
No problem if I'm using implicit linking (inclufing the headerfile in my application, and linking to the lib-file)
Is it possible to use the exported class when using explicit linking (Loadlibrary and GetProcAddress)
TIA
|
|
|
|
|
Anders Molin wrote: Is it possible to use the exported class when using explicit linking (Loadlibrary and GetProcAddress)
No, explicit linkage can only retrieve the address of a function. It cannot 'import' a class.
But, you could still do it using a little 'trick': use a function that create the class instance and returns it. Or even better: it returns an interface of the class (this way, you only need to distribute the header containing the interface with your dll and not the cpp file of the class)
|
|
|
|
|
Yeah, I was already planning to just export en "interface", eg. a class with only abstract functions.
But if my function returns a pointer to a class derived from the interface, can the application just use it then (if it have the header file)?
If multible applications or dll's lolad my dll, is there any way to make sure they get a pointer to the same instance of the class?
Yes, I'm not that good with DLL's, it's really one of my weeker sides
|
|
|
|
|
Anders Molin wrote: But if my function returns a pointer to a class derived from the interface, can the application just use it then (if it have the header file)?
Don't return a pointer to the derived class but to the base class. So it should look like this (this code is only in the dll):
class CBaseClass
{
};
class CChildClass : public CBaseClass
{
};
DLL_EXPORT CBaseClass* GetClass
{
return new CChildClass;
}
In this way, the application will only need to know the interface of the class (so you won't need to add the cpp file of your child class in the application that uses the DLL).
Anders Molin wrote: If multible applications or dll's lolad my dll, is there any way to make sure they get a pointer to the same instance of the class?
For this part, I don't know. The 'standard' singleton pattern won't work in this case because static variables in your dll are not accessible from the application.
|
|
|
|
|
Thanks
I did plan to just return a pointer to the base class, I did express it badly. Sorry...
Cedric Moonen wrote: For this part, I don't know. The 'standard' singleton pattern won't work in this case because static variables in your dll are not accessible from the application.
Exactly...
My DLL is loaded from multible DLL's which are all loaded from a single application... The class is some communication layer, and all the different dll's need to get a pointer to the same instance of this class so they all can send data through the same TCP connection... (does that make sense?)
Any ideas anyone?
|
|
|
|
|
I believe yes, the same way you can allocate and return a pointer to a struct from a DLL's function and still be able to access its members in the calling application.
You have to make sure that both the DLL and the calling application agree on the object being returned. Normally, sharing the same .H file for the object does the trick, but when dealing with objects that have a vtbl in them, you need to also watch out for implementation-specific details. For example, if MS VC++ puts the vtbl at the beginning of the object in memory, and MinGW's gcc expects it at the end of the object in memory, you will not be able to share the DLL between the two. The same technically goes for references, but all implementations I have experience with use pointers behind the scenes. (Trivia: this is why you can pass a pointer to an object to an exported VC++ function that expects a reference to one and it will work correctly).
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Hello,
I have a query regarding recordset retrieval. This is what I have so far.
1.An SDI application(name:Database) without database support and CDatabaseView derived from CFormView
2.A second dialog(name:Dialog1) and its class Cdialog1.
3.A new MFC class CMySet derived fron Crecordset.
4.CDialog1 has a foreign variable m_pSet of type CMySet
The DB connection opens properly using CDatabse.OpenEx()
then i have the following code to open a recordset. "user" is one of the tables I have selected.
CDialog1 dlg;
dlg.m_pSet = new CMySet(m_pDB);
str = "SELECT * FROM User;";
dlg.m_pSet->Open(AFX_DB_USE_DEFAULT_TYPE,str,CRecordset::none)
I get an error at this point, while executing,saying "error retrieving record".Actually on clickin a button on the first main form(which just has a pic) I wanted to have a screen for username and password whiich has to be verified from the DB.
Am i wrong in my approach somewhere. the application builds and compiles jus fine. Kindly help.
|
|
|
|
|
namratab wrote: I get an error at this point, while executing,saying "error retrieving record".
So why don't you step into the Open() call to see what's going on?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
ACtually, the exact same Open call worked in another small aplication. The only difference was that the object invoking the Open() method was of type REcordSEt...and in my case it is of a type MySEt ( derived from recordSEt)
|
|
|
|
|
But until you actually step into the Open() call, you'll not know the cause of the error.
I've only done one article dealing with record sets. See if this is of any help.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
How do I check to see if the 8th bit in a byte is set to a 1 or 0? Thanks
|
|
|
|
|
Use the bitwise '&' operator.
BYTE mybyte = 0x80;
if ( ( mybyte & 0x80 ) != 0x00 )
|
|
|
|
|
|
And I thought it was written for me
|
|
|
|
|
lol, no Mark, you're not a beginner AFAIK. but if you consider yourself to start with bitwise stuff, then yes, you're all understood to bookmark it
|
|
|
|
|
Awww thanks man!
|
|
|
|
|
I'm working on a project which involves printing invoices. Those invoices have predefined layouts (more than one) which may contain tables(of purchased products), images and so on. What should i use for displaying/printing them?. I've used an activex ie control and XML/XSL generated pages for this kind of work in the past but now i need pagination and some other features that html cannot provide. Generating pdf files is also an option but i don't know which api to use
|
|
|
|
|
Straight ASCII and Form Feed characters! :P
Seriously, I would think that something like PDF would work well here, as would something like a reporting package (like Crystal Reports).
There are APIs that allow you to programmatically create a PDF document, but I do not know of any free ones.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
there are some but...well...i need something more than a txt2pdf thing
|
|
|
|
|
Hi,
Please help me find a way to disable or change the color of the selection highlighting in a CTreeCtrl. It is the same selection highlighting that is expanded by enabling the "FullRowSelect" option of a CTreeCtrl.
Thanks.
|
|
|
|
|
Hi,
I try to translate text to text in True DBGrid control, but it seems not work in VC++, my code list below:
....
CValueItems oValueItems;
oValueItems = m_CtrlTDBG.GetColumns().GetItem(&index).GetValueItems();
CValueItemDisp* pValueItemDisp = new CValueItemDisp();
pValueItemDisp->SetValue(old_value);
pValueItemDisp->SetDisplayValue(new_value);
oValueItems.Add((LPDISPATCH)pValueItemDisp);
oValueItems.SetTranslate(TRUE);
....
I don't know how to use the function CValueItems.Add(LPDISPATCH vItem), someone can give me any suggestion? Thanks!
|
|
|
|
|
liur17 wrote: I don't know how to use the function CValueItems.Add(LPDISPATCH vItem), someone can give me any suggestion? Thanks!
what type of TrueDB grid are using.... UnBounded or bounded
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Thanks for your reply.
I use True OLE DataGrid 7, using bound mode.
Looking forward to your instruction, Thank you in advance.
|
|
|
|
|
Hello !
I want to find out whether the current logged in user is Domain user or a Local system user. What I mean Is whether user is logged to Domain or a local system.
Is there any API I can use to determine this???
Thanks.
|
|
|
|
|
sach!! wrote:
Is there any API I can use to determine this???
Possibly. Check out NetUserGetInfo() and NetWkstaUserGetInfo() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|