Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GetModuleFileName instance and registering app

GetModuleFileName instance and registering app

Scheduled Pinned Locked Moved C / C++ / MFC
c++windows-adminquestionworkspace
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Raymond So
    wrote on last edited by
    #1

    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

    D I M 3 Replies Last reply
    0
    • R Raymond So

      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

      D Offline
      D Offline
      Dave Bryant
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • R Raymond So

        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 Offline
        I Offline
        igor1960
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • R Raymond So

          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

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups