|
If you move this code to .exe, does it work OK?
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Inside an .exe it works fine!
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Try setting the hInstance parameter of the WNDCLASS structure to NULL GetModuleHandle(NULL) .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, but it doesn't work
modified 12-Sep-18 21:01pm.
|
|
|
|
|
And if you replace also the hInstance occurrence in CreateWindow ?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Same result, no window is created
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Ummm this is getting weird. In which context is CreateLogWindow being called? Does a message pump exist in the calling EXE? Please note that whether CreateLogWindow is inside a DLL or the EXE itself is immaterial from the system point of view (if you used GetModuleHandle(NULL) throughout), so the behavior observed is really odd.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
CreateWindow is called from the DllMain function:
BOOL APIENTRY DllMain( HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved )
{
hInstance = hModule;
if (dwReason == DLL_PROCESS_ATTACH)
{
CreateLogWindow(hInstance);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
}
return TRUE;
}
And I think the EXE has a message pump since it has a main window.
Probably there is to mention that my Dll is one using the Microsoft Detours libary. Perhaps you know about it. My Dll attaches itself to an exe and thus can interupt Api calls from the main app and modify them.
This way I want to intercept the send() and sendto() functions in order to watch what the apps are sending. The window I want to create shall display the buffer of send() and sendto()
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Could you trace where the error is hapenning? RegisterClass , CreateWindow , everything silently working but no window appears?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I just mixed up two different names for the class in the WNDCLASS style and CreateWindow.
Tim Smith found the error here: http://www.codeproject.com/script/comments/forums.asp?forumid=1647&select=147264#xx147264xx
Thanks anyway
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I'm glad the mistery solved This bears a moral (IMHO): when you said the same code worked inside an EXE, you obviously used some other code that you deemed equivalent (otherwise the same problem persists). Many debugging efforts are lost due to this kind of assumptions.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
You need a DLLMain (entry point) function for the DLL. Here's an example pulled from MSDN...
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpReserved )
{
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Take the instance param from that function and pass it to your CreateLogWindow() function. Use that instanace in the window's class. This is the done the same way you would use WinMain in an executable.
Also, don't forget to specify the entry point to the linker when compiling the DLL -- this has to be done.
Jeremy L. Falcon
"The One Who Said, 'The One Who Said...'"
<nobr>
Homepage : Feature Article : Sonork = 100.16311
|
|
|
|
|
Well, hInstance HAS the value of hinstDLL.
But what do you mean by
Jeremy Falcon wrote:
don't forget to specify the entry point to the linker when compiling the DLL
?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
The entry point is the starting address of the DLL -- the first of your code that's called. You need to let the linker know about it.
You need a user-defined entry point for the DLL. I believe it defaults to DLLMain, but if your DLL doesn't use that naming you must specify it somehow. I chose using the linker and specify it anyway regardless. I'm crazy like that.
I'm assuming you're using VC6...
Goto project settings.
Link Tab
Category: Output
You'll see an edit box for the Entry-point symbol. Put the name of your entry function in there.
Jeremy L. Falcon
"The One Who Said, 'The One Who Said...'"
<nobr>
Homepage : Feature Article : Sonork = 100.16311
|
|
|
|
|
Ummm...
The class name in WndClass is "Testprogramm" and in CreateWindow it is "LogWindow".
Hopefully that is it.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Ummm how stupid
I just corrected it and suddenly it works
Thanks a lot!
modified 12-Sep-18 21:01pm.
|
|
|
|
|
So how did you manage to run this code from .exe?
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
It think I copy&pasted the code and later changed some strings, but unfortunately not all
really stupid
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi Tim! You must be in a fresher mental state than I am, how simple yet elusive. The duck's for you
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
It's amazing how really looking at the code helps. That deserves a doh for me too!
Jeremy L. Falcon
"The One Who Said, 'The One Who Said...'"
<nobr>
Homepage : Feature Article : Sonork = 100.16311
|
|
|
|
|
Hehehe, when I saw what the problem was, I knew everyone was going to kick themselves for not seeing it.
We have all looked at code for 30 hours on end just to have some jackass spend 5 minutes looking over our shoulder and see the problem.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I have a CListCtrl that I would like to put images onto. I create a bitmap and bitblt an image into it, this works fine as I have tested that the image in the bitmap is valid by printing it to the screen. When I add this bitmap to the CImageList then accociate it with the CListCtrl a black box appears next to the column instead of my image! Here is the code I am using (I have tried many different values but I think it has something to do with the bitmap not being compatible or something)
CDC dc, *pDC = GetDC();
CBitmap cBmp;
m_ChatNicksImages.Create(16, 16, ILC_COLORDDB | ILC_MASK, 8, 1);
dc.CreateCompatibleDC(pDC);
cBmp.CreateCompatibleBitmap(pDC, 16*8, 16);
dc.SelectObject(cBmp);
m_Skin.BitBlt(&dc, 0, 0, 16*8, 16, 195, 250);
m_ChatNicksImages.Add(&cBmp, RGB(0, 255, 0));
m_ChatNicksCtrl.SetImageList(&m_ChatNicksImages, LVSIL_SMALL);
cBmp.DeleteObject();
ReleaseDC(pDC);
These are members of my dialog:
CImageList m_ChatNicksImages;
CListCtrl m_ChatNicksCtrl;
Any help is appreciated, Thanks.
|
|
|
|
|
At the time you are trying to add the bitmap to the image list, it is still selected into your memory device context. You should restore the previous bitmap before continuing:
dc.CreateCompatibleDC(pDC);
cBmp.CreateCompatibleBitmap(pDC, 16*8, 16);
CBitmap* pBmpOld = dc.SelectObject(&cBmp);
m_Skin.BitBlt(&dc, 0, 0, 16*8, 16, 195, 250);
dc.SelectObject(pBmpOld);
Note also that you want to pass a pointer to the bitmap into dc.SelectObject() (as i've shown).
Sometimes i only remember, The days when i was young Nowadays no one remembers when they were young and stupid... ADEMA, The Way You Like It
|
|
|
|
|
Thank you this worked perfectly!
|
|
|
|
|
I want to specify a ‘default’ printer that may not be the Windows users default printer when the print dialog executes.
This code works, but I am concerned about a few of areas.
1.) See where I’m using the cp variable to update the printer name? Could this code overwrite memory beyond the area allocated for the printer name?
2.) Notes from the HELP file indicate I should free the DC. Do I need to do that? How would I do it?
3.) I’m saving and restoring flags to get the print dialog to display. I bet there is a better solution to that problem, what is it?
CPrintDialog dlg(FALSE,
PD_ALLPAGES |
PD_HIDEPRINTTOFILE |
PD_NOPAGENUMS |
PD_RETURNDC |
PD_USEDEVMODECOPIES);
/*
We are saving the current Flags here so we can put them back after the call
to GetDefaults()... calls to DoModal() will not pop the dialog unlesss we
do this.
rgc
*/
DWORD save_flags = dlg.m_pd.Flags;
dlg.GetDefaults();
/* **** from the HELP files ****
Note that when you call the constructor with bPrintSetupOnly set to FALSE,
the PD_RETURNDC flag is automatically used. After calling DoModal,
GetDefaults, or GetPrinterDC, a printer DC will be returned in m_pd.hDC.
This DC must be freed by the caller of CPrintDialog.
*/
LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(dlg.m_pd.hDevNames);
// next line is test code to get the current printer
//LPCTSTR lpszDevice = (LPCTSTR)lpDev + lpDev->wDeviceOffset;
char *cp = (char *)lpDev + lpDev->wDeviceOffset;
CString def_prn = "\\\\MCL002NT\\CLIREQ";
strcpy(cp,def_prn);
// next line is test code to check to see that the printer has changed
//lpszDevice = (LPCTSTR)lpDev + lpDev->wDeviceOffset;
/*
Restore the saved flags so we can pop the dialog with DoModal().
rgc
*/
dlg.m_pd.Flags = save_flags;//PD_RETURNDEFAULT = FALSE;
::GlobalUnlock(dlg.m_pd.hDevNames);
dlg.DoModal()
// - - - - - - - - - - - - -
Rick Crone
|
|
|
|