|
Hi there,
Please answer to my questions about DLL …
Q1.
I want to write simple function in a Win32 DLL project …
And call that by LoadLibrary …
I made a Win32 DLL project …
Then I wrote this function in .h file:
__declspec(dllexport) void SayHello();
And I wrote it in .cpp file:
void SayHello()
{
MessageBox(NULL, “Helllllllllo !”, “Info”, MB_ICONINFORMATION);
}
Then I compiled it without any problem …
In my MFC exe project …
I loaded that:
CoInitialize(NULL);
HMODULE hModule = LoadLibrary( "test4.dll" );
FARPROC procFunc;
procFunc = GetProcAddress(hModule, "SayHello");
(procFunc)();
FreeLibrary(hModule);
CoUninitialize();
There is no problem in DLL path file, I checked it …
But when I run this code, program show me this error:
“Unhandled exception in testdll.exe : 0x0000005 : Access violation.”
What is my wrong ?
Q2.
If I write a DLL by MFC DLL, can I use of that from other programming language like Delphi or VB ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
are you testing hMoudle or procFunc for NULL ? you should.
-c
I don't care, and you can't make me.
|
|
|
|
|
Ok,
hMoudle returned value ...
But procFunc returned NULL !!!
Can you help me, please ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
The reason that GetProcAddress returns NULL is because the SayHello function does not exist in your dll. C++ Name mangling would change that to an entry like this: SayHello@@YAXXZ. I answered this question with more detail in the other thread.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
You are having a problem with the name mangling that the c++ compier does on functions. The compiler will generate and export this symbol instead:
SayHello@@YAXXZ
So if you want to call load library on this function, then you need to ask for that symbol instead. If you chang the signature of the function, the mangling will change as well, so you will have to use the Depends tool that came VC++ to determine what the name of the exported symbol is.
If you would like to turn off name mangling for this function you can prepend your function definition with this:
extern "C" void SayHello();
About your second question, yes you will be able to use your functions from a DLL in Delphi or VB as long as you only declare functions, if you would like to use a class that you exported from an MFC or a C++ DLL then you will need to create a COM component to represent that class. Also, I would recommend turning off name mangling if you plan on using these functions in Delphi or VB.
Good Luck.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Hi dear kilowatt
Thanks for reply ...
I got confused
I runed Dependes program and that show me this function in my DLL: ?SayHello@@YAXXZ
In fact, i want to use this DLL in Delphi program ...
Now, Please please please tell me how could i fix it ?
I must make .DEF file ?
But i don't know what i must write in that !!!
Plz help me ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Your function is failing to be found by GetProcAddress because it is not called SayHello, it is name mangled and the new name is SayHello@@YAXXZ.
In order to make the name of your exported function be just a plain SayHello, you will need to declare it like this in your header file:
extern "C" _declspec(export) void SayHello();
The _declspec(export) directive is probably a macro definition in your file. Anyway, the extern "C" defintion will turn off name mangling and you will be able to refer to your function just as SayHello rather than SayHello@@YAXXZ.
I am not that familiar with Delphi, but if you are supposed to declare a .DEF file in order to use the DLL, then you should declare the SayHello function int he IMPORTS section of this file. I think you will then need to link your delphi program with the .lib file that is created for your DLL.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Thanks alooot kilowatt,
Yes, now IT WORKS FINE !
I used .DEF file for it ...
Regards,
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Sample .def file
; myfile.def : Declares the module parameters for the DLL.
LIBRARY "mylib" BASE=0x10000000 ; change the base to something better
; to avoid collisions with other modules
DESCRIPTION 'does a lot of useful stuff'
EXPORTS
myFunction ; no parameters or anything else, just name of function
myOtherFunction
This will turn off mangling as well as setting some useful parameters, like the default base address. Set this to something other than 0x1000000 as this is the default base for C++ modules (speed up loading time that way).
/moliate
Two o'clock and walking through familiar London - Or what was familiar London before the cursor deleted certain certainties -
I watch a suit and tie man giving suck to the Psion Organizer lodged in his breast pocket
its serial interface like a cool mouth hunting his chest for sustenance, familiar feeling, and I'm watching my breath steam in the air.
Neil Gaiman - Cold Colours
|
|
|
|
|
Hello moliate,
Thanks alooooooooooooooooooooot for your help.
IT WORKS
I can't believe it !
Now it works fine ...
Now i think, i can go and sleep in rest !
Really thanks and thank you for simple .DEF ...
I just have other question ...
If i define a enum like this:
enum Days
{
sunday = 0;
saturday = 1;
};
or classes and strctures ...
How about them ?
How could i define them in .DEF file ?
I must write only their names in .DEF ?
Regards,
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hadi_Rezaie wrote:
If i define a enum like this:
...
or classes and strctures ...
Those go in the header file.
However: using structs and classes as function parameters should generally be avoided, as it severly cripples the ability to use the module with other languages. Besides the fact that different languages have different memorylayout for classes, many languages can't handle pointers. Try keeping the module as neutral as possible.
BTW, I noticed that you were calling CoInitialize before loading the module. As you are using an ordinary dll (non-COM) that is not neccissary..
Cheers
/moliate
Two o'clock and walking through familiar London - Or what was familiar London before the cursor deleted certain certainties -
I watch a suit and tie man giving suck to the Psion Organizer lodged in his breast pocket
its serial interface like a cool mouth hunting his chest for sustenance, familiar feeling, and I'm watching my breath steam in the air.
Neil Gaiman - Cold Colours
|
|
|
|
|
Because it dont like these signature I also stick to the good old def-file and get my undecorated names.
|
|
|
|
|
Hi All,
Any idea why this wouldn't work?
BOOL bRes = m_cAnimCtrl.Open("PROGRESS.AVI");
if (bRes)
{ m_cAnimCtrl.Play(0, -1, -1);
}
Progress.avi exists in the same folder as the project and opens fine in Media Player.
Cheers,
Clodagh.
|
|
|
|
|
Maybe it's too complex for CAnimateCtrl to handle. Docs say something like it has to be uncompressed or RLE8, whitout palette changes ad a couple more restrictions. Try replacing with a simpler AVI to determine if this could be the cause.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
The video is uncompressed. It's just a standard clock on a progress dialog - nothing fancy )
|
|
|
|
|
Maybe its a path problem. Your app runs in another directory. Try the complete path. What ist with GetLastError() ???;)
|
|
|
|
|
Sub : Out of Memmory when loading the Project into the workspace
we are developing a small appl for storing images into a database using VC++ 6.0. Entr Edition. The database used is SQL Server 7.0. The problem facing is the image is not storing in the database. When trying to save the image an error is poping up saying "Invalid Locator de-referenced". When the same program is connected with Access 2000, it working fine.
Another problem facing is, sometimes, when we open the Project, it will not load. System saying that "Out of Memmory", mainly when loading resource file.
The machine config is i think quite okay, 128 mb, 500 Mhz Processor Speed (Pentium 3) with 1GB free space in the primary drive.
Thanks in advance
|
|
|
|
|
Hi
I have a problem and hope you can help. I have a software that creates a registry key unter HKEY_LOCAL_MACHINE/Software. Because of some Problems with that I had to change the access rights on the key SOFTWARE and add an user there and said in the regedt32 program that it shall exchange the access rights also for the sub keys too.
When I run my software and it creates the new key then this key géts automatical the same access rights from the SOFTWARE-key.
To make it easier for my customers I wanted to write a small tool that adds this special user and the access right to the SOFTWARE-key automatical and changes the access rights for the subkeys too (people are scared to work with regedt32 and change something).
Everything works fine ... I read the current users and add the new user to that key and then I go through the subkeys and make the same changes. The only problem is that when my original software is running and creates its own key that new key doesn't get the access rights from the SOFTWARE-key. My guess is that the tickmark in the regedt32 dialog is doing something else than just going through the tree and exchanging the access rights but also tells the main key that it shall monitor if new subkeys are created and give it its own new access rights too or something like that. Now the problem is that I don't know how to make my tool doing the same. Is there some kind of flag or function that I have to call so that every new created subkey has to get the same access rights like the SOFTWARE-key?
Thank you for your help
Grit
|
|
|
|
|
YOu can do this, but it's a little ugly. How I managed to do this was:
Get security settings of the key I'd like to emulate (e.g., HKLM\Software)
Set security settings on my new key to the settings I just got.
Check out RegGetKeySecurity and RegSetKeySecurity and that should put you in the right direction.
No generalization is 100% true.
Not even this one.
|
|
|
|
|
The Problem is that I'm NOT allowed to change the software who is creating that new
subkey so it would set the security settings by it's own like that.
Grit
|
|
|
|
|
Hi! Could somebody tell me how can i access the properties of standard C++ and additional AciveX controls?
I used VB before C and i was used to get/set a property using a simple command like (TextBox1.Text="Anything or else"'. But in C++ i cannot do this so simple. I tried to add a member variable (using the class wizard) for a CString type value(m_Text1) and for the control(Text1) either but they just don't work. The CString shows no connection between it and the value (it's always empty), and when i try to use the var. for the control (Text1.GetWindowText and Text1.GetLine) it says: unhandled error at 0x0000005?).
Please somebodi tell me the solution! Thanks!
Vis
|
|
|
|
|
OK, I will have a stab at this. Even though I have been drinking beer and haven't written any code in close to 6 months due to no job and to much reading and looking after kids.
Let's say you have a control called Ctrl1, you set the text using Ctrl1.SetWindowText("NewTitle") and retrieve the current value using Ctrl1.GetWindowText(StrToStore).
I hope that is what you were asking.
Michael Martin
Australia
mjm68@tpg.com.au
"He orginally got the Tweezers of Destruction through the scanners but then popped back outside for a smoke."
- Chris Maunder 26/03/2002
|
|
|
|
|
take a look at "UpdateData()"
it tranfers the text from the controls to the CString or from the CString to the controls
if very easy to use when you have many control in one dialog
you can also use the "SetWindowText" and the "GetWindowText" but you will have to write more code to get the same thing done
|
|
|
|
|
the problem is that;
you tried to access a CString type EditBox variable as if u are using a CEdit (control type) variable. GetWindowText and GetLine is available for control type variables. You can use the value whatever u write in EditBox inside your code easily getting the value (be it character or number) by UpdateData(TRUE); or display the new value (if u changed it inside ur code) by UpdateDate(FALSE)...
Visual C++ is not a toy..you will understand me in the future...
just listening to you...
|
|
|
|
|
I've got a modeless dialog box which can be resized and I would like to set a minumum size for it, as it looks stupid if it is too small. Any ideas?
I tried editing the OnSize function like this (thinking that if it worked I could check for 'cx < MINIMUM_X' and change cx if required):-
void CDlg::OnSize(UINT nType, int cx, int cy)
{
cx = 200;
cy = 300;
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
}
It didn't work, the dialog stayed the same size. And when I looked at cx and cy in the debugger their values did not change (they were 605 & 573 when it entered the function and the same when CDialog::OnSize was called). I am very confused about why they did not change . Can anyone help?
Any comments welcome .
ali p
|
|
|
|