Thursday, March 6, 2014
How to Connect VB6.0 VC++
1. Click “Start,” “All Programs” and “Visual Basic 6” to open VB6.0. Click “File,” 'New Project” and “ActiveX DLL” to create an ActiveX DLL file. Change the project name to “dllfile” in the Property window. Click “Save” to save the project to your local computer.
2. Click “Project” and “References” to add Excel references to the existing reference list:
C:\Program Files\Microsoft Office\Office11\Excel.exe. This has the reference set up to Microsoft Excel Object Library.
3. Click dllfile.vb on the “Solution Explorer” and enter the following code after the “Option Explicit declaration”:
Implements AddInDesignObjects.IDTExtensibility2
4. Create a new class module by right-clicking the project name, and select “New class.” Enter the following code:
Option Explicit
Option Compare Text
Private WithEvents pExcelApp As Excel.Application
Friend Property Get ExcelApp() As Excel.Application
Set ExcelApp = pExcelApp
End Property
This class module defines Excel application events. Click “File,” “Add Project” and “Standard EXE” to compile it. Locate the complied file from where you saved your project.
5. Click “Start,” “All Programs” and “VC++.” Click “New” and “Project” to create a new project. Click “Form1.vc” and include the dll file:
#include “dllfile.dll”
6. Load the DLL into memory and create an instance of it:
HINSTANCE hLib = LoadLibrary('dllfile.dll');
if(hLib == NULL)
{
cout
getch();
return;
}
7. Search through the DLL file and find the address of functions:
TestFunc = (cfunc)GetProcAddress((HMODULE)hLib,'TestFunc');
RetInt = (ifunc)GetProcAddress((HMODULE)hLib,'RetInt');
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment