如果要按要求说的那样,也只有把DLL大包放入资源了,实际上这样有时也是有必要的
至少我以前的一个程序里就是这样做的……
写一个RC文件内容如……
ZIPDLL RCDATA "zipdll.dll"
UNZDLL RCDATA "unzdll.dll"
直接在project manager里加入到当前project里即可
然后使用前展开,如
with TResourceStream.Create(hInstance, 'ZIPDLL', RT_RCDATA)do
try
SaveToFile(ExtractFilePath(ParamStr(0)) + 'ZIPDLL.DLL');
finally
Free;
end;
用完删除……如果需要注册……看看下面的代码
以前用BCB写的,懒得转成DELPHI,
凑合着看吧,反正差不多的……应该够详细了吧,hehe
bool __fastcall TfrmMain::RegisterIt(const AnsiString strFileName) const
{
/*
STARTUPINFOA si;
PROCESS_INFORMATION pi;
AnsiString AppName(NormalDir(GetSystemDir()) + "RegSvr32.exe"),
CmdLine(" /"" + strFileName + "/"");
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW;
return CreateProcess(AppName.c_str(), CmdLine.c_str(),
NULL, NULL, false, 0, NULL, NULL, &si, &pi);
*/
bool bResult;
HINSTANCE hOcx = LoadLibrary(strFileName.c_str());
try
{
FARPROC DllRegisterServer = GetProcAddress(hOcx, "DllRegisterServer");
if(NULL == DllRegisterServer)
bResult = false;
else
bResult = (S_OK == DllRegisterServer());
}
__finally
{
FreeLibrary(hOcx);
}
return bResult;
}
//---------------------------------------------------------------------------
bool __fastcall TfrmMain::RegisterOcx(void) const
{
AnsiString SystemDir = NormalDir(GetSystemDir());
if(FileExists(SCRIPT_CONTROL_OCX))
{
return RegisterIt(AnsiString(NormalDir(ExtractFilePath(ParamStr(0))) + SCRIPT_CONTROL_OCX));
}
else
{
if(FileExists(SystemDir + SCRIPT_CONTROL_OCX))
{
return RegisterIt(SystemDir + SCRIPT_CONTROL_OCX);
}
else
{
dlgOpenOcx->InitialDir = SystemDir;
dlgOpenOcx->FileName = SCRIPT_CONTROL_OCX;
if(dlgOpenOcx->Execute())
return RegisterIt(dlgOpenOcx->FileName);
else
return false;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::Init(void)
{
try
{
SC = CreateOleObject(PID_SCRIPT_CONTROL);
}
catch(EOleSysError &E)
{
if((CO_E_CLASSSTRING == E.ErrorCode) ||
(REGDB_E_CLASSNOTREG == E.ErrorCode))
{
if(RegisterOcx())
{
SC = CreateOleObject(PID_SCRIPT_CONTROL);
}
else
{
MessageDlg("控件注册失败,程序无法正常使用!", mtError, TMsgDlgButtons() << mbAbort, 0);
Application->Terminate();
}
}
else
throw;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
Init();
}