GetModuleFileName instance and registering app
-
I'm trying to place a value in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run so that my app starts up when windows starts up, as a background app. I've implemented DLLRegisterServer so that it is invoked when the setup.exe runs (I've set the .exe to self-register under InstallShield). In DLLSelfRegister, I need the path to the .exe so that the value in the registry is set properly and the .exe runs from that path. I use GetModuleFileName to get the path of the app, but when regsvr32 myApp.exe is run, the app is not instantiated yet. I used MFC to create a dialog based app Here's a code snipet: CSysTrayDemoApp theApp; //MFC generated ... //Implement this funciton so that regsvr32 can invoke it to register exe. STDAPI DllRegisterServer() { char path[MAX_PATH]; DWORD pathLen = sizeof(fileName); __asm int 3; GetModuleFileName(theApp.m_hInstance, path, pathLen); ... theApp.m_hInstance is not instantiated and thus I can't get the path name. Does anyone have experience in registering an app/is there a better way of doing this? Thanks, Raymond
-
I'm trying to place a value in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run so that my app starts up when windows starts up, as a background app. I've implemented DLLRegisterServer so that it is invoked when the setup.exe runs (I've set the .exe to self-register under InstallShield). In DLLSelfRegister, I need the path to the .exe so that the value in the registry is set properly and the .exe runs from that path. I use GetModuleFileName to get the path of the app, but when regsvr32 myApp.exe is run, the app is not instantiated yet. I used MFC to create a dialog based app Here's a code snipet: CSysTrayDemoApp theApp; //MFC generated ... //Implement this funciton so that regsvr32 can invoke it to register exe. STDAPI DllRegisterServer() { char path[MAX_PATH]; DWORD pathLen = sizeof(fileName); __asm int 3; GetModuleFileName(theApp.m_hInstance, path, pathLen); ... theApp.m_hInstance is not instantiated and thus I can't get the path name. Does anyone have experience in registering an app/is there a better way of doing this? Thanks, Raymond
Try passing in NULL as the HINSTANCE for GetModuleFileName() - that means it retrieves the name of the current module. The most likely reason for theApp.m_hInstance not being initialised is that DllRegisterServer normally does not need to call DllMain(), so your normal application initialisation has not occurred. Dave http://www.cloudsofheaven.org
-
I'm trying to place a value in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run so that my app starts up when windows starts up, as a background app. I've implemented DLLRegisterServer so that it is invoked when the setup.exe runs (I've set the .exe to self-register under InstallShield). In DLLSelfRegister, I need the path to the .exe so that the value in the registry is set properly and the .exe runs from that path. I use GetModuleFileName to get the path of the app, but when regsvr32 myApp.exe is run, the app is not instantiated yet. I used MFC to create a dialog based app Here's a code snipet: CSysTrayDemoApp theApp; //MFC generated ... //Implement this funciton so that regsvr32 can invoke it to register exe. STDAPI DllRegisterServer() { char path[MAX_PATH]; DWORD pathLen = sizeof(fileName); __asm int 3; GetModuleFileName(theApp.m_hInstance, path, pathLen); ... theApp.m_hInstance is not instantiated and thus I can't get the path name. Does anyone have experience in registering an app/is there a better way of doing this? Thanks, Raymond
As you are registering EXE -- this is outproc server. Why would you need regsvr32 for that (it's used for inproc servers)? Instead, you should start your outproc server with /REGSERVER and process it properly in yours InitInstance (or whatever)... "...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..." Me
-
I'm trying to place a value in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run so that my app starts up when windows starts up, as a background app. I've implemented DLLRegisterServer so that it is invoked when the setup.exe runs (I've set the .exe to self-register under InstallShield). In DLLSelfRegister, I need the path to the .exe so that the value in the registry is set properly and the .exe runs from that path. I use GetModuleFileName to get the path of the app, but when regsvr32 myApp.exe is run, the app is not instantiated yet. I used MFC to create a dialog based app Here's a code snipet: CSysTrayDemoApp theApp; //MFC generated ... //Implement this funciton so that regsvr32 can invoke it to register exe. STDAPI DllRegisterServer() { char path[MAX_PATH]; DWORD pathLen = sizeof(fileName); __asm int 3; GetModuleFileName(theApp.m_hInstance, path, pathLen); ... theApp.m_hInstance is not instantiated and thus I can't get the path name. Does anyone have experience in registering an app/is there a better way of doing this? Thanks, Raymond
EXEs aren't registered with
DllRegisterServer()
(as the name says, "DLL"). You should instead register in response to being run with/RegServer
. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber CP SearchBar v2.0.2 released