有个API用来注册.ocx的
Declare Function RegComCtl32 Lib "C:\name.dll" _
Alias "DllRegisterServer" () As Long
Declare Function UnRegComCtl32 Lib "C:\name.dll" _
Alias "DllUnregisterServer" () As Long
Const ERROR_SUCCESS = &H0 使用:
 call RegComCtl32
If RegComCtl32 = ERROR_SUCCESS Then
MsgBox "注册成功!"
Else
MsgBox "注册失败!"
End If试试看?

解决方案 »

  1.   

    以下是VC的方法,使用更灵活一些。
    不过不能改成VB的.At this point, add the following code segment, which will allow you to check the return codes from LoadLibrary(), GetProcAddress(), and DllRegisterServer. 
    #ifdef _WIN32
        HINSTANCE hDLL = LoadLibrary("some.ocx");
        if(NULL == hDLL)
        {
            // See Winerror.h for explaination of error code.
            DWORD error = GetLastError();
            TRACE1("LoadLibrary() Failed with: %i\n", error);
            return FALSE;
        }    typedef HRESULT (CALLBACK *HCRET)(void);
        HCRET lpfnDllRegisterServer;    lpfnDllRegisterServer =
                (HCRET)GetProcAddress(hDLL, "DllRegisterServer");
        if(NULL == lpfnDllRegisterServer)
        {
            // See Winerror.h for explaination of error code.
            DWORD error = GetLastError();
            TRACE1("GetProcAddress() Failed with %i\n", error);
            return FALSE;
        }    if(FAILED((*lpfnDllRegisterServer)()))
        {
            TRACE("DLLRegisterServer() Failed");
            return FALSE;
        }#else // 16-bit
        HINSTANCE hDLL = LoadLibrary("regtest.ocx");
        if(HINSTANCE_ERROR > hDLL)
        {
            // See LoadLibrary() help for explaination of error code.
            TRACE1("LoadLibrary() Failed with: %i\n", hDLL);
            return FALSE;
        }    typedef HRESULT (CALLBACK *HCRET)(void);
        HCRET lpfnDllRegisterServer;    lpfnDllRegisterServer =
                (HCRET)GetProcAddress(hDLL, "DllRegisterServer");
        if(NULL == lpfnDllRegisterServer)
        {
            // See GetProcAddress() help for explaination of error code.
            TRACE("GetProcAddress() Failed");
            return FALSE;
        }    if(FAILED((*lpfnDllRegisterServer)()))
        {
            TRACE("DLLRegisterServer() Failed");
            return FALSE;
        }
    #endif 
      

  2.   

    非常谢谢大家的解答! 谢谢!
    有关API DllRegisterServer的不解:请问如果我要注册一个DLL 如 Test.DLL.完整的代码是什么?只DllRegisterServer()一个函数怎么完成注册啊?我的Test.DLL怎么传进去呢?不然又怎么知道我要注册的是哪个DLL呢? 
    期待中.....
      

  3.   

    Declare Function RegComCtl32 Lib "C:\test.dll" _
    Alias "DllRegisterServer" () As Long我不是写了吗?声明时就将test.dll引入啊!你试试看吧!
      

  4.   

    http://www.applevb.com/art/Control.txt,看看!
      

  5.   

    dragon525() 你的方法我不能用。我的DLL不确定。不过结合你与上面VC的程序我问题已经解决了。谢谢大家!