mIRC Home    About    Download    Register    News    Help

Print Thread
DLL problem #113092 01/03/05 06:09 AM
Joined: Mar 2005
Posts: 7
G
Goblin Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Mar 2005
Posts: 7
Hello,


I'm trying to make a small DLL for mIRC, and I'm in a situation where I need a handler for my dll (ModuleHandle of type HMODULE). In a generic DLL application this is passed to DllMain(), but since the structure of an mIRC DLL is different I have no access to that.

Also, I tried using LoadLibrary() but I had no luck in getting a Module Handle (to my dll). The reason why I need a Module Handle is that I have some resources (dialogs), and when I call these dialogs (with DialogBox()) it tries to open mIRC's dialogs rather the ones defined in my resource file, it seems it operates on the parent process (mIRC in this case) unless I provide a specific ModuleHandle (well, in this case I'm trying to get the Module Handle of my DLL).



Your help is greatly appreciated.




Thank you.

Re: DLL problem #113093 01/03/05 07:06 AM
Joined: Jun 2003
Posts: 195
N
Narusegawa_Naru Offline
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
mIRC dll's are no different than any other dll. you can include a DllMain function in it as well. Just make sure you export it like any other function


Have Fun smile
Re: DLL problem #113094 02/03/05 02:11 AM
Joined: Mar 2005
Posts: 7
G
Goblin Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Mar 2005
Posts: 7
Great! Thanks a lot!

Somehow I had in my mind that I have to include only the functions that my dll will explicitly call. (but, now, DllMain() will be called _each_ time I do a /dll or $dll in mIRC, right? or just the first time it's loaded?)

Also, another question rises now...

If I need to use the dll handle (passed to DllMain) in the rest of my functions, what would be the best way to do that? Maybe declare a global variable and set it to the dll handle in DllMain? or somehow use a pointer to point to the dll handle?



Thanks once again.

Re: DLL problem #113095 02/03/05 05:35 AM
Joined: Jun 2003
Posts: 195
N
Narusegawa_Naru Offline
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
it depends. DllMain is called each time the dll is loaded or unloaded. By default mirc unloads the dll after your call (/dll etc...) however you can use LoadDll (as well as UnloadDll) to instruct mirc to keep the dll loaded. this will play into the other question.

Ya just create a global HINSTANCE for your dll handle just remember to keep the dll loaded (globals go out of scope otherwise)


Have Fun smile
Re: DLL problem #113096 03/03/05 11:53 PM
Joined: Mar 2005
Posts: 7
G
Goblin Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Mar 2005
Posts: 7
Thanks. Things went pretty well... though, I'm getting more trouble now...


The thing I'm trying to do is... well, I have a dialog (defined in my resource script, resource.rc), and I'm trying to call or "bring up" that dialog with DialogBox(). The thing is, it always return -1 (error), and the dialog never shows up. Now I don't know what part I'm doing wrong, but can you please help me with this? I've tried asking the folks at #winprog on EFNet, but they couldn't help much with this. I've also doubled checked at MSDN and my call to DialogBox seems correct. Here's what I have:


Code:
 
	int ret = DialogBox(hmod, MAKEINTRESOURCE(IDD_ABOUT), NULL, AboutDlgProc2);
	if(ret == -1) {
		MessageBox(mWnd, "Dialog failed!", "Error", MB_OK | MB_ICONINFORMATION);
	}


It always shows "Dialog failed!". hmod is a global variable that points to hinstDLL (that is passed to DllMain). IDD_ABOUT is some integer (I tried different ones), and AboutDlgProc2 is the dialog's message handler. I don't really see what the problem is....

Re: DLL problem #113097 04/03/05 08:01 AM
Joined: Jun 2003
Posts: 195
N
Narusegawa_Naru Offline
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
well lets start with the obvious. the identifier for the resource is assigned by VS when you add the dialog. If you go to resource view and right click the dialog then select properties one of the items in the window (near the bottom) will be the identifier.

This number isnt arbitrary. The value used on the resource (the dialog itself) and the value used in the call to DialogBox MUST be the same.

The best thing for you to try now would be a call to GetLastError. heres what you should do

SetLastError(0);
DialogBox(...);
GetLastError();

obviously place in your code. you can place the value in a string and MsgBox it. Once you have that value click on tools->Error lookup and place the value in. It will give you a descriptive message (allbeit cryptic sometimes) of what went wrong.

Let me know what value you get and we'll go from there.

P.S check your dialog proc remember you MUST return TRUE to the WM_INITDIALOG message of the dialog isnt created and DialogBox fails (similar to WM_CREATE for a window).


Have Fun smile
Re: DLL problem #113098 05/03/05 01:08 AM
Joined: Mar 2005
Posts: 7
G
Goblin Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Mar 2005
Posts: 7
I don't use VS, I have CodeWarrior. I set the #defines for these resources myself (there's no visual editor, so I edit the .rc file myself), sometimes I have IDD_ABOUT set to 100 and sometimes to 123 and sometimes to any random number (just to make sure it's not the resource ID that's making the problem), so, I define IDD_ABOUT and use it in DialogBox(). This is probably not the problem.


What's weird is, when I called GetLastError() after the Dialog Failed, it returned 0, which is "Operation completed successfully". I don't really know what's wrong.

--------------------
(ADDED LATER)
--------------------


Well, I found something interesting. I had a "LIBRARY" line in my .def file like:

LIBRARY mDLL2

I removed that and now I'm getting an error number of 1814, which is:

The specified resource name cannot be found in the image file.

What image file? I already have a #define IDD_ABOUT 1000
at the top of my DLL.

Last edited by Goblin; 05/03/05 01:29 AM.
Re: DLL problem #113099 05/03/05 01:30 AM
Joined: Jun 2003
Posts: 195
N
Narusegawa_Naru Offline
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
as long as the same identifier is used in both places it should be fine just trying to throw out some things you may not have thought of.

Did you remember to check the WM_INITDIALOG case of the dialog procedure? If you dont need it just make sure you return TRUE for msg's you dont catch or trap.

Something else you may want to try is calling LoadLibrary yourself. I remember you said you had once but just to make sure. Im almost certain that isnt it. You may also want to make sure DllMain is indeed being called. simply place a msgbox in the DLL_PROCESS_ATTACH case in DllMain.

Im not familliar with that ide so i wont be able to help you much there. If i think of anything else ill let you know. Keep me informed however : )


Have Fun smile
Re: DLL problem #113100 06/03/05 02:45 AM
Joined: Mar 2005
Posts: 7
G
Goblin Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
G
Joined: Mar 2005
Posts: 7
I don't really know. It seems my IDE doesn't deal with resources quite well (according to some reviews I've read). WM_INITDIALOG is fine. It returns TRUE for everything actually since this is just a minimal test dialog with only some text and an ok/cancel button. DllMain is called too.

I better get VS then confused



Thanks for all of your help though, I really appreciate it.



Have a good day.

Re: DLL problem #113101 06/03/05 04:33 AM
Joined: Jun 2003
Posts: 195
N
Narusegawa_Naru Offline
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
sorry i couldnt help more. I like VS but alot of people would advise against it since it is quite expensive. I believe theres a free (limited) edition of VC on microsofts site but i dont have a link. You may also be qualified to get a student edition for a smaller price.

I would suggest that wether you use VS or not getting an installable version of the MSDN is alot easier and helpfull than thier online one.


Have Fun smile
Re: DLL problem #113102 12/03/05 12:05 AM
Joined: Mar 2003
Posts: 187
S
Soul_Eater Offline
Vogon poet
Offline
Vogon poet
S
Joined: Mar 2003
Posts: 187
what kind of dll is it?

Re: DLL problem #113103 24/03/05 04:29 PM
Joined: Jul 2003
Posts: 77
B
bamaboy1217 Offline
Babel fish
Offline
Babel fish
B
Joined: Jul 2003
Posts: 77
well uhh that library line you remove is important lol

LIBRARY dllName
EXPORTS
exPortedFN
AnotherExpOrtedFn
... etc


hmmm signed by me