Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - Reading a resource in a DLL. | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 6631/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 08-29-05 06:11 AM Link | Quote
Alright, so through some reading and experimentation, I've pretty much got DLLs down pat. I can load one and use it, I can make one, and I can have one call a function in the EXE that loaded it. But there's one other thing I need to do. I need to have an EXE load a resource, located in a DLL, into memory (preferrably without actually loading and initializing the DLL). It needs to be relatively fast, because there could potentially be a lot of DLLs to look through. So how would I go about doing that?
Dish

Spiny
Level: 38

Posts: 541/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 08-29-05 06:41 AM Link | Quote
All resource loading functions take an HINSTANCE parameter as the instance which the resource resides in. Typically this is your exe (so you use the instance passed to WinMain), however for loading from DLLs, you just pass the instance of the DLL.

I think the instance of the DLL is what's returned from LoadLibrary() (even though it's referred to as 'HMODULE' rather than 'HINSTANCE') but it's been a while. Try passing the HMODULE returned from LoadLibrary to a resource loading function and see if that works. I'm pretty sure that's what you do, but I'm not 100%
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 6632/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 08-29-05 07:24 AM Link | Quote
Alright, but I don't really know much about resources to begin with. What resource loading function would I use?

And is there a faster alternative to StretchBlt?


(edited by HyperHacker on 08-28-05 10:24 PM)
sloat

Level: 16

Posts: 76/85
EXP: 18044
For next: 2212

Since: 05-21-04
From: South Central Delaware

Since last post: 19 days
Last activity: 5 hours
Posted on 08-29-05 10:12 AM Link | Quote
LoadImage for icons, bitmaps, and cursors. Alternatively, there are LoadIcon, LoadBitmap, etc. functions but don't have as many options.
FindResource and LoadResource for loading misc data. The msdn page for LoadResource actually has a list of the functions to use for which type of resource.

And Disch is right, the return value of LoadLibrary is what you want to specify as the module handle for the various resource functions.

The only GDI alternative to StretchBlt is StretchDIBits...but it requires using a DIB and probably isn't worth it (and probably isn't faster either). Using DDraw or D3D could be much faster, but might not be worth the pain of setting up.
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 6638/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 08-29-05 10:49 AM Link | Quote
Thanks, I'll check that out.

Anyone know how to show the standard Open File dialog? I've never actually done it in C.
Dish

Spiny
Level: 38

Posts: 542/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 08-29-05 10:57 AM Link | Quote
Fill out an OPENFILENAME struct and pass it to GetOpenFileName() or GetSaveFileName() to launch a standard open file / save as box. Try looking up OPENFILENAME on MSDN for a list of the struct members.

*goes to fish example code*




char path[MAX_PATH] = "";

OPENFILENAME ofn;
memset(&ofn,0,sizeof(OPENFILENAME));

ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hMainWnd;
ofn.lpstrFilter = "Dat Files (*.dat)\0*.dat\0All Files\0*\0\0";
ofn.lpstrDefExt = ".dat";
ofn.nFilterIndex = 1;
ofn.lpstrFile = path;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_LONGNAMES | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;

if(!GetOpenFileName(&ofn))
{
//message box errored. Or (more likely), the user hit Cancel. Abort
}
else
{
// perform the load. 'path' contains the selected path
}




There are lots of config tweaks though -- I still highly recommend looking up OPENFILENAME to see what's all available.
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 6652/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 08-29-05 11:58 AM Link | Quote
Well as long as I have a function/structure to search for. Searching on MSDN when you don't have a specific name is like trying to find a quarter you dropped in the middle of ocean.

[edit] So... How the hell do I use combo boxes? I set the CBS_HASSTRINGS, CBS_DROPDOWN, WS_CHILD and WS_VISIBLE styles and added 256 strings, with no errors being reported, go to click it, and nothing happens. Not even a CBN_DROPDOWN message, except once when the window opens and once when it closes.


(edited by HyperHacker on 08-29-05 10:08 PM)
sloat

Level: 16

Posts: 77/85
EXP: 18044
For next: 2212

Since: 05-21-04
From: South Central Delaware

Since last post: 19 days
Last activity: 5 hours
Posted on 08-30-05 10:20 AM Link | Quote
Combo boxes are a little tricky. The height parameter when creating it is used for the height of the combo plus the height of the drop down list. It's the same with a dialog editor. Make sure that's not your problemo.
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 6702/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 08-31-05 03:50 AM Link | Quote
That's probably it. This stupid editor forces them to be 13 pixels high. I'll have to fiddle with that later. Right now I'm more concerned with how to get a child window's coordinates relative to its parent's client area. I can get them relative to the parent's position, but that includes the title bar and border, and I don't see any way to determine their size.
Dish

Spiny
Level: 38

Posts: 546/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 08-31-05 04:47 AM Link | Quote
GetWindowRect should get you the position and size of the control in relationship to the screen (not relative to any other window). You can then use ScreenToClient to convert those coords to coords relative to the parent window's client area.

You can also use MoveWindow to move/resize a control/window. Although the coords you pass it are relative to the parent's client area -- but of course you can use ScreenToClient / ClientToScreen for converting.


(edited by Disch on 08-30-05 07:49 PM)
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 6708/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 08-31-05 06:49 AM Link | Quote
Ah, that's what I was looking for.

Is there a function to draw on a DC using its background colour (erase it), or get its BG colour/brush?
Dish

Spiny
Level: 38

Posts: 547/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 08-31-05 07:26 AM Link | Quote
I never needed to, so I dunno if there's an easier way than this...

but it looks like you can get the WNDCLASSEX struct which the window class was registered with (which contains the background brush) by calling GetClassInfoEx(). You need to give the class name (the string) the window was registered with -- to get that from an HWND you can call GetClassName()
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 6777/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 09-02-05 08:15 AM Link | Quote
Yeah, that did it.

For some reason, though, this is corrupting memory:

(in ctrlevent.c)
switch(OptID)
{
case MLINK_TOP:
i = GetConnectionIndex(CONNECTION_TOP);
y = i;
if(i>0)
{
sprintf(TempStr[0],"No map linked at top.");
SetText(GetDlgItem(hWindow[DLG_MAIN],MAIN_LBL_STATUS),TempStr[0]);
break;
}
if(!SavePrompt()) break;
if(y != i) DebugOut(DO_MAJOR,"Connection error, i=%d (should be %d)\n",i,y);
LoadMap(Map.Connection[i].DestMap);
break;
[the same stuff repeated with different variables]
}


(in map.c)
BOOL SavePrompt()
{
if(MapSaved) return true;
int rc = MessageBox(hWindow[DLG_MAIN],"Would you like to save the current map?","Save",MB_YESNOCANCEL | MB_ICONQUESTION);
if(rc == IDCANCEL) return false;
if(rc == IDYES)
{
MessageBox(0,"SavePrompt(): TODO: Save map!","Hey!",MB_ICONEXCLAMATION);
}
return true;
}


i and y are global integers and somehow both are getting corrupted when SavePrompt() gets called. i is usually either 2 or 70, and y is 6, 7 or 15, when neither should be above 4 (in this particular case both should be below 2). Without the SavePrompt() call it works fine.

[edit] Here's another fun problem. The Control key is virtually sticking. If I press Control once, GetKeyState() returns True until I press it again. Nevermind, it was the toggle bit. Dunno why Control can be toggled but yeah.

[more editing] Any way to set a window's client size? Like give it a size and it automatically adjusts the window?


(edited by HyperHacker on 09-01-05 11:18 PM)
(edited by HyperHacker on 09-03-05 05:20 PM)
(edited by HyperHacker on 09-03-05 05:26 PM)
(edited by HyperHacker on 09-03-05 10:24 PM)
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - Reading a resource in a DLL. | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.009 seconds.