CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2002
    Location
    Nebraska
    Posts
    25

    Register DLL in Another App

    Hey, I have a COM/ATL dll that I created for automating word. I have another application, written in C, that I need to open MS Word and load my dll. I know how to do all of this, but I am having a problem registering my dll. I currently do this:

    //register the dll
    WinExec("regsvr32 /s WordAddin.dll", SW_SHOWNORMAL);
    rc = RegOpenKeyExHKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Office\\Word\\Addins\\Word.Addin", 0, KEY_ALL_ACCESS, &hKey);

    if(rc != ERROR_SUCCESS)
    {
    WinExec("regsvr32 /s /u WordAddin.dll", SW_SHOWNORMAL);
    WinExec("regsvr32 /s WordAddin.dll", SW_SHOWNORMAL);
    }

    At the end of my processing, I am unregistering the dll. It seems to work part of the time. The problem is that every once in a while, I click the button to launch MS Word from w/in my application but the dll is not getting registered. When I go out and manually look in the registry, it is not in the there. I have no idea why it is not registering the dll. Can anyone help or give me some insight into why this is happening and how I can fix it? I have looked and there are LOTS of posts about registering dlls and from what I could tell, I am doing it correctly. But something is wrong and I do not know what. It happens sporadically. PLEASE HELP!!!!!

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    Oh dear, we are in a tizzy !

    Firstly, before all else : you should NOT !! be calling regsvr32 by using WinExec.

    In fact you shouldn't use WinExec at all, but use CreateProcess instead.

    But by the by.

    If you want to register a dll, then use LoadLibrary to load the dll,
    and get the pointers to the functions DllRegisterServer and DllUnregisterServer and use those.

    If you call regsvr32.exe explicitly inside of your code, then what happens is it creates A NEW PROCESS to do the registering - the function doesn't wait around for the regsvr32.exe process to finish before doing the next one.

    This is very highly probable to be your problem.

    If you need further guidance about LoadLibrary & GetProcAddress - the function you'll need to get the address of the DllRegisterServer() and DllUnregisterServer() functions - then have a look at the sample for regsvr32 in MSDN - yep, there's a sample program.

    Darwen.

  3. #3
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    Sorry, to clarify.

    By calling the regsvr32.exe several times using WinExec (or CreateProcess, doesn't matter) then sometimes the one you call later will finish before the one you call ealier. This is because neither WinExec nor CreateProcess waits for the exe to finish before continuing.

    You're intermittent problem is caused by this very fact.

    You DEFINATELY need to call the registering functions in the dll directly. Then, magically, everything will work as expected.

    Darwen.

  4. #4
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by darwen
    You DEFINATELY need to call the registering functions in the dll directly.
    Why?
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  5. #5
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    I might misunderstand something. Is it normal to register and unregister addins like that? Or is there a reason for doing the temporary registration such as this?
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  6. #6
    Join Date
    May 2002
    Location
    Nebraska
    Posts
    25
    The reason for my temporary registration is that I have an application, written in C. It does many things including allow the user to enter text. I have a text editor, nothing fancy. But I wanted to allow the user the opportunity to use MS Word. So when they hit the Enter Text button, it will pop up either the text editor or MS Word. If I register the dll inside the dll, then this will not work. Also, I am adding a special button that will save the current document as a specific filename and exit MS Word. If I register the dll inside the dll, this button will show up every time word is opened, even if it is opened outside of my application. So I more or less have to register it in the application, not in the dll...

  7. #7
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882
    Why dont you try real registration functions..
    Load the DLL dynamically Get address to RegisterServer and UnregisterServer function and call them as you need.......Dont call WinExec.It has got limitations over CreateProcess and is deprecated.
    Regards,
    Ramkrishna Pawar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured