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.
  
User name:
Password:
Reply:
 

UserPost
HyperLamer
Posts: 6777/8210
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?
Dish
Posts: 547/596
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
Posts: 6708/8210
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
Posts: 546/596
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.
HyperLamer
Posts: 6702/8210
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.
sloat
Posts: 77/85
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
Posts: 6652/8210
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.
Dish
Posts: 542/596
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
Posts: 6638/8210
Thanks, I'll check that out.

Anyone know how to show the standard Open File dialog? I've never actually done it in C.
sloat
Posts: 76/85
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
Posts: 6632/8210
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?
Dish
Posts: 541/596
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
Posts: 6631/8210
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?
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.011 seconds.