|
hi
are you trying to destroy a window in that window's class
deconstructor? I think when deconstructor is called, the
window is already destroyed, so no message can be sent to it,like WM_DESTROY( which invokes OnDestroy).
|
|
|
|
|
QUESTION 1:
i just want to confirm that I can register and unregister my ATL-COM wizard created server by calling LoadLibrary and invoke DllRegisterServer/DllUnregisterServer directly - as opposed to command line util Regsvr32.
For some reason, the code is not working, and with no compiler or runtime error - I cant even tell if the function call has been executed. I know however that the register the component does not exist in registry - after i run the following subroutine:
//TO UNREGISTER SERVER:
int UnRegQueryGen(char * pszDll)
{
DWORD dwError;
typedef STDAPI (*PFUNC) (void); //QUESTION 2: This will cause : error C2159: more than one storage class specified
//So, I changed it to:
typedef void (*PFUNC) (void); //and it seems to work fine (i.e. no compiler error)
//<caution! quote="" from="" msdn..="">
//If the string specifies a path but the file does not exist in the specified directory, the function fails. When specifying a path, be sure to use backslashes (\), not forward slashes (/).
//STEP 1: Load dll.
HINSTANCE hLib;
hLib = LoadLibrary(_T(pszDll));
//STEP 2: un-register server
if(hLib!=NULL)
{
PFUNC pFunc = NULL;
pFunc = (PFUNC) GetProcAddress(hLib, _T("DllUnregisterServer"));
if(pFunc!=NULL)
{
//Unregister the server!
pFunc();
}
else
{
//Additional exception handling here.
dwError = GetLastError();
FreeLibrary(hLib);
return 0;
}
}
else
{
//Additional exception handling here.
dwError = GetLastError();
return 0;
}
FreeLibrary(hLib);
return 1;
}
//TO REGISTER A SERVER
int RegQueryGen(char * pszDll)
{
typedef void (*PFUNC) (void);
//STEP 1: Load dll.
HINSTANCE hLib;
hLib = LoadLibrary(_T(pszDll));
//STEP 2: register server
if(hLib!=NULL)
{
PFUNC pFunc = NULL;
pFunc = (PFUNC) GetProcAddress(hLib, _T("DllRegisterServer"));
if(pFunc!=NULL)
{
//register the server!
pFunc();
}
else
{
//Additional exception handling here.
FreeLibrary(hLib);
return 0;
}
}
else
{
//Additional exception handling here.
return 0;
}
FreeLibrary(hLib);
return 1;
}
One last point, the exposed DllRegisterServer and DllUnregisterServer is implemented by ATL Wizard, so, I dont think there's anything to do with it.
Thanks!
norm
|
|
|
|
|
Hi.
I am working on a project that contains a formview class with multiple dialog windows visible. As the user make changes to each dialog box, I want to update the document class. I implemente a message solution. The dialog boxes update send messages to the view class. The view class update the document class.
In general, the solution above is adequate. However, in this particular project, the dialog windows are visible in the formview. I would like to know is there other more elegant solutions?
For example, is it possible to implement a GetDocument() function that returns a pointer to the document class inside the dialog boxes? As another example, how about passing the dialog boxes pointers to the document class? I do not want to implement these solution unless messages fail. Thus these solutions should be last resorts.
Thanks,
Kuphryn
|
|
|
|
|
I'm sure there are a million answers to your question. But I would stick to the message solution. It is the best way for windows to communicate. I would not pass pointers to class objects around to be used. That could be potentially dangerous. If the WPARAM and LPARAM parameters seem to limiting remember you can allocate memory (or objects; classes, structs, etc.) and pass the pointer to another window through a message.
if(IsWindow(hwnd))
{
CThing *pThing = new CThing;
PostMessage(hwnd, WM_NEW_THING, 0, (LPARAM)pThing);
} Just remember the receiver of the message is responible for deleting the memory.
long CMyWnd::OnNewThing(WPARAM wParam, LPARAM lParam)
{
ASSERT(lParam);
CThing *pThing = (CThing *)lParam;
...
delete pThing;
} One more thing, in the OnDestory method of the CWnd class make sure you have no more WM_NEW_THING messages in the queue. Their memory should be deleted if they are.
MSG msg;
while(::PeekMessage(&msg, (HWND)NULL, WM_NEW_THING, WM_NEW_THING, PM_REMOVE))
{
CThing *pThing = (CThing *)msg.lParam;
delete pThing;
} Hope this helps.
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
Recommendation noted.
Thanks,
Kuphryn
|
|
|
|
|
where can get stuff about these?
|
|
|
|
|
The easiest way is to put a batch file that does it onto the PC in question and execute it remotely.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
hi, what's wrong with copying a file with fread and fwrite?
int CopyQueryGenDll(char * pszOutfile)
{
FILE *stream;
//Size of QueryGenAlpha.dll = 249 kB
int nDllSize = 1000;
char * buffer = new char[nDllSize];
if(buffer==NULL)
{
//Exception handling here.
return 0;
}
int i=0;
int numread = 0;
int numwritten = 0;
//Initialize buffer:
for(i=0; i
|
|
|
|
|
1) You're trying to read and write a binary file in text mode - the carriage return line feed translations are going to screw it up.
2) Why not just use CopyFile()?
Dave
|
|
|
|
|
thanks, just did. i tried to stay with stdio.h because it's more portable - in case if any part of the code needs to be deployed under a UNIX environment.
norm
|
|
|
|
|
Hi!
I always wondered why VC6 and VC.NET do not use multiple compiler instances when running on a SMP box. On unix running gnu make in parallel mode is just an argument away. Why can't have this on VC too?
|
|
|
|
|
How many PC's have more than one processor ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Seems like a chicken and egg question to me .
I'm pretty sure many developers would buy SMP machines if their compiler could use the power to divide compile times by two!
All my dev machines are SMP for quite simple reasons, the first being that programming multithreaded code and testing it only on mono proc machines is one of the best way to shoot one slef in the foot .
|
|
|
|
|
MeeLoo wrote:
the first being that programming multithreaded code and testing it only on mono proc machines is one of the best way to shoot one slef in the foot
I'll give you that, in a second. However, this is Microsoft who until now have not given us partial template specialisation because, well, no Windows programmer uses it. Of COURSE we don't use it, they have not let us.....
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Hehe .
That's probably why lobbying for features like these can be important, no?
Sebastien
|
|
|
|
|
I guess so - good luck !!!
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
QUESTION 1:
i typed at the command prompt:
C:\somefolder\regsrv32 mysever.dll
Error from regsrv32: "myserver.dll" is not an executable file and no registration help is registered for this file type.
and
C:\somfolder\regsrv32 /u myserver.dll
Error from regsrv32: same as above.
It's an ATL-Wizard created COM btw.
QUESTION 2:
btw, I also tried to register and unregister with WinExec. Is there anything wrong? forward slashes Vs back slashes?
#include "stdafx.h"
#include <windows.h>
#include <iostream.h>
int main(int argc, char* argv[])
{
int nRetCode = 0;
nRetCode = WinExec("RegSvr32 /u C:\Program Files\RealTime7\QueryGenAlpha\QueryGenAlpha.dll", SW_SHOW);
if(nRetCode <= 31)
{
cout << "WinExec failed..." << endl;
}
return 0;
}
The error was not reported thru the console (ie. nRetCode>31), but:
(a) A pop up from regsvr32 appeared, and:
"LoadLibrary("C:Program" failed - the specified module cannot be found"
(b) I also tried to call LoadLibrary from client directly. But LoadLibrary failed. And GetLastError() reported after call to LoadLibrary:
193 is not a valid Win32 application. ERROR_BAD_EXE_FORMAT
Code as follows:
HINSTANCE hLib;
hLib = LoadLibrary(_T(pszDll));
//STEP 2: un-register server
if(hLib!=NULL)
{
PFUNC pFunc = (PFUNC) GetProcAddress(hLib, _T("DllUnregisterServer"));
if(pFunc!=NULL)
{
//Unregister the server!
pFunc();
}
else
{
//Additional exception handling here.
dwError = GetLastError();
return 0;
}
}
else
{
//Additional exception handling here.
dwError = GetLastError();
return 0;
}
One last thing: When I build (Ctrl-F5) the ATL COM server project, I had no problem at all. THe server get registered, and I tested the server from VB client and it worked!
Thanks!
norm
|
|
|
|
|
just found this link:
http://support.microsoft.com/default.aspx?scid=KB;en-us;q249873
not sure if i can spot the problem....
norm
|
|
|
|
|
i figured out the problem, the dll was corrupted in the process of copying it from CD to destination folder.. anyway, i fixed that. Now i tried to LoadLibrary to access DllUnregisterServer and DllRegisterServer...
i load the dll via LoadLibrary and called:
STEP 1: GetProcAddress(hLib, _T("DllUnregisterServer")
proceed to un-register the dll.
STEP 2: GetProcAddress(hLib, _T("DllRegisterServer")
proceed to register the dll.
i still have some trouble. i lauch the VB client and it stop working. tried to open keys from registry and registry complained "error openning key" ... (somehting close to that)
since DllRegisterServer is implemented by ATL Wizard, I assume there's nothing wrong with it (MS never produces buggy code right? )
so, THREE prime suspect:
SUSPECT 1:
PFUNC pFunc = (PFUNC) GetProcAddress(hLib, _T("DllRegisterServer")); //SUSPECT 1: Name mingling.. but pFunc is NOT NULL. So, this is cleared.
if(pFunc!=NULL)
{
//register the server!
pFunc();
}
SUSPECT 2:
typedef void (*PFUNC) (void);
does it matches the signature of..?
STDAPI DllRegisterServer(void)
I am a bit confused by STDAPI, but I just ignore it for the moment... But SUSPECT 2 is the only remaining p
ossibility i can see.
SUSPECT 3:
the installation program i write now call DllUnregisterServer before installing a clean copy. But the old dll may reside in a different folder.
if I call DllUnregisterServer by loading the new dll (in attempt to unregister the old dll...?) you think this will be a problem?
SUSPECT 4:
RegSvr32 does more than just load the dll and call DllRegisterServer and DllUnregisterServer. Developer should not attempt to call these two methods directly and should stick with RegSvr32?
norm
|
|
|
|
|
hi
have you tried this?
nRetCode = WinExec("RegSvr32 /u \"C:\\Program Files\\RealTime7\\QueryGenAlpha\\QueryGenAlpha.dll\"", SW_SHOW);
|
|
|
|
|
thanks for the feedback... i tried, and it worked just well:
char szCommand[300];
for(i=0; i<300; i++)
{
szCommand[i]='\0';
}
strcpy(szCommand, pszQueryGenDir);
strcat(szCommand, "/RegSvr32.exe QueryGenAlpha.dll");
WinExec(szCommand, SW_SHOW);
but RegSrv32 pop up is really annoying... I cant get LoadLibrary working unfortunately..
i'm suspecting that something is wrong with the function pointer:
typedef HRESULT (STDAPICALLTYPE *PFUNC)() ; //OPTION 1: It worked!!?
//typedef void (*PFUNC) (void); //OPTION 2: It Does NOT WORK???
WHY????
Here's the code:
int i = 0;
DWORD dwErr = NULL;
OleInitialize(NULL);
typedef HRESULT (STDAPICALLTYPE *PFUNC)() ; //OPTION 1: Requires stdole.h
//typedef void (*PFUNC) (void); //OPTION 2: Wont work unfortunately. U wont even get a compiler/RT error.
char * pszDll = NULL;
pszDll = new char [300];
for(i=0; i<300; i++)
{
pszDll[i] = '\0';
}
strcpy(pszDll, pszQueryGenDir);
strcat(pszDll, "\\QueryGenAlpha.dll");
//STEP 1: Load dll.
HINSTANCE hLib;
hLib = LoadLibrary(_T(pszDll));
dwErr = GetLastError();
//STEP 2: register server
if(hLib!=NULL)
{
PFUNC pFunc = NULL;
pFunc = (PFUNC) GetProcAddress(hLib, _T("DllRegisterServer"));
dwErr = GetLastError();
if(pFunc!=NULL)
{
//register the server!
pFunc();
dwErr = GetLastError();
}
else
{
//Additional exception handling here.
FreeLibrary(hLib);
return 0;
}
}
else
{
//Additional exception handling here.
return 0;
}
dwErr = GetLastError();
FreeLibrary(hLib);
delete [] pszDll;
OleUninitialize();
Thanks
norm
|
|
|
|
|
hi
have you traced the program execution? does it get to the
pFunc() calling? does it come out of that call back to
your program?
|
|
|
|
|
it did work, for whatever odd reason. all that i changed was the typedef, as i indicated earlier.
i dont understand it. just followed as instructed. be nice if someone can give a bit of explanation though.
norm
|
|
|
|
|
Debug Assertion Failed!!
Program: c:\myproject\myprogram.exe
File: olecli3.cpp
Line: 502
For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts
What would be the reason of getting this error message and why I didnn't get it before. The program get no changes, I simply go to debug folder and double clicked on the exe file to run my program... the program was working fine prior to the time I got this error message. After that, I can't event run my program at all.
what would be causeing this error??
Thanks you
|
|
|
|
|
File: olecli3.cpp
Line: 502
Make sure you don't look at the above file at the above line, as it could give you a strong hint at what is going wrong.
Seriously, go to that file at that line, and there is agood chance you figure out what is wrong. If not, post the content here (with some context) and we may be able to help you.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|