I wanted to know the win32 API to run the regsvr32 programatically.
I have one application through which I can communicate with 开发者_高级运维COM port devices. but to achieve communication, I have to register MSCOMM32.ocx using regsvr32.exe, But now I wanted to add this provision in my code. so that no need to run regsvr manually.
The windows CreateProcess API call is what you're looking for: http://msdn.microsoft.com/en-us/library/ms682425(v=vs.85).aspx
You can do it using a combination of win32 api calls:
- LoadLibrary() to load the Dll
- GetProcAddress() to get the address of the DllRegisterServer() function
- If GetProcAddress finds that function, call it to register the Dll.
The DllRegisterServer function is explained here: MSDN: DllRegisterServer Entry Point
You've already had the answer to the title of the question.
As for registering the DLL, I presume you're using VB6 with which you can not (easily) register it directly.
The correct way to register it is to do it as part of the installer.
Doing it in the app is too late as you (most likely) won't normally have the admin permissions required to register it.
To ask the user to run it as an admin, you can use ShellExecute() and pass "runas" as the verb with "regsvr32.exe" and the path to mscomm32.ocx as the file and parameters.
For VB6:
ShellExecute 0, "runas", "regsvr32.exe", """c:\blah.dll""", "c:\", 0
精彩评论