Я решаю проблему после большого количества поиска в Google. Это код, из которого моя проблема решена. Мне не нужен нативный код для этого ..
#include "stdafx.h"
#include "stdafx.h"
#include <Msi.h>
#include <WinUser.h>
#include "windows.h"
#include <afxwin.h>
#include <afx.h>
#include <WinSpool.h>
#include <assert.h>
#include <WinBase.h>
#include "resource.h"
#define IDR_DLL1 101
#define IDR_EXE1 102
bool ExtractDll(const HINSTANCE hInstance, WORD resourceID, LPCTSTR szOutputFilename);
bool ExtractExe(const HINSTANCE hInstance, WORD resourceID, LPCTSTR szOutputFilename);
bool cmd();
CString AppPath();
#define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
#import "dv.tlb" named_guids raw_interfaces_only
using namespace dv;
UINT __stdcall Validation( MSIHANDLE hModule )
{
/*BOOL qw = ExtractDll(AfxGetResourceHandle(), IDR_DLL1, _T("C:\\VBDLL.dll") );
BOOL qw1 = ExtractExe(AfxGetResourceHandle(), IDR_EXE1, _T("C:\\RegAsm.exe") );*/
BOOL qw = ExtractDll(AfxGetResourceHandle(), IDR_DLL1, (LPCTSTR)(AppPath() + _T("\\dv.dll")) );
if (qw == false)
{
return ERROR_INSTALL_USEREXIT;
}
BOOL qw1 = ExtractExe(AfxGetResourceHandle(), IDR_EXE1, (LPCTSTR)(AppPath() + _T("\\RegAsm.exe")) );
if (qw1 == false)
{
return ERROR_INSTALL_USEREXIT;
}
BOOL retCmd = cmd();
if (retCmd==false)
{
return ERROR_INSTALL_USEREXIT;
}
IkeyvalidationPtr pICalc(__uuidof(SetupClass));
long retun =0;
BSTR strVer = SysAllocString(L"4.0.1517");
pICalc->keyValidation(strVer,&retun);
if (retun==1)
{
return ERROR_INSTALL_USEREXIT;
}
return ERROR_SUCCESS;
}
CString AppPath()
{
try
{
TCHAR path [MAX_PATH];
ITEMIDLIST* pidl;
HRESULT hRes = SHGetSpecialFolderLocation( NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE , &pidl );
if (hRes==NOERROR)
{
SHGetPathFromIDList( pidl, path);
}
CString apPath;
apPath = path;
apPath = apPath + _T("\\path");
CreateDirectory((LPCWSTR) apPath,NULL);
return apPath;
}
catch(...)
{
}
}
bool cmd()
{
CString m1=_T('');
CString temp1 = _T("");
CString temp = temp1 + _T('"');
//CString s1 = temp + AppPath() + _T("\\RegAsm.exe"); // Cascading concatenation
CString s1 = temp + AppPath() + _T("\\RegAsm.exe") + _T('"'); // Cascading concatenation
CString s2 = _T(" /codebase");
CString message = s1 + _T('"')+ _T(' ')+ _T('"') + AppPath() + _T("\\dv.dll") + _T('"') +_T(' ') + _T("/tlb:")+('"') + AppPath() + _T("\\dv.tlb") + _T('"')+ s2;
CString message1 = _T('"') + AppPath() + _T("\\dv.dll") + _T('"') +_T(' ') + _T("/tlb:")+('"') + AppPath() + _T("\\dv.tlb") + _T('"')+ s2;
SHELLEXECUTEINFO ExecuteInfo;
memset(&ExecuteInfo, 0, sizeof(ExecuteInfo));
ExecuteInfo.cbSize = sizeof(ExecuteInfo);
ExecuteInfo.fMask = 0;
ExecuteInfo.hwnd = 0;
ExecuteInfo.lpVerb = L"runas"; // Operation to perform
ExecuteInfo.lpFile = s1;
ExecuteInfo.lpParameters = message1; // Additional parameters
ExecuteInfo.lpDirectory = 0; // Default directory
ExecuteInfo.nShow = SW_HIDE;
//ExecuteInfo.nShow = SW_SHOW;
ExecuteInfo.hInstApp = 0;
if(ShellExecuteEx(&ExecuteInfo) == FALSE)
{
return false;
}
return true;
}
bool ExtractDll(const HINSTANCE hInstance, WORD resourceID, LPCTSTR szOutputFilename)
{
TCHAR sResName[5] = _T("#101");
TCHAR sRestype[4] = _T("DLL");
HRSRC hres = FindResource(AfxGetResourceHandle(), sResName,sRestype);
if (hres == 0)
{
return false;
}
HGLOBAL hbytes = LoadResource(hInstance, hres);
// Lock the resource
LPVOID pdata = LockResource(hbytes);
DWORD dwSize = SizeofResource(hInstance, hres);
HANDLE hFile = CreateFile(szOutputFilename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
/// INSERT DATA IN FILE
HANDLE hFilemap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwSize, NULL);
LPVOID lpBaseAddress = MapViewOfFile(hFilemap, FILE_MAP_WRITE, 0, 0, 0);
try
{
RtlCopyMemory(lpBaseAddress,pdata,dwSize);
}
catch ( ... )
{
return false;
}
UnmapViewOfFile(lpBaseAddress);
CloseHandle(hFilemap);
CloseHandle(hFile);
return true ;
}
bool ExtractExe(const HINSTANCE hInstance, WORD resourceID, LPCTSTR szOutputFilename)
{
/*LPTSTR sArgv = argv[1];
LPTSTR sArgv2 = argv[2];*/
TCHAR sResName[5] = _T("#102");
TCHAR sRestype[4] = _T("EXE");
//HINSTANCE Nl=AfxGetInstanceHandle();
HRSRC hres = FindResource(AfxGetResourceHandle(), sResName, sRestype);
if (hres == 0)
{
return false;
}
HGLOBAL hbytes = LoadResource(hInstance, hres);
// Lock the resource
LPVOID pdata = LockResource(hbytes);
DWORD dwSize = SizeofResource(hInstance, hres);
HANDLE hFile = CreateFile(szOutputFilename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
/// INSERT DATA IN FILE
HANDLE hFilemap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwSize, NULL);
LPVOID lpBaseAddress = MapViewOfFile(hFilemap, FILE_MAP_WRITE, 0, 0, 0);
try
{
RtlCopyMemory(lpBaseAddress,pdata,dwSize);
}
catch ( ... )
{
return false;
}
UnmapViewOfFile(lpBaseAddress);
CloseHandle(hFilemap);
CloseHandle(hFile);
return true;
}
Это код MFC, из которого решена моя проблема. Этот код встраивает ресурсы, извлекает ресурсы и регистрирует библиотеку типов во время выполнения.