Подключение lcomp.dll - VB
Формулировка задачи:
Уважаемые гуру в программировании помогите горю.В VB6 новичёк . Есть плата ввода/вывода на PCI шину и lcomp.dll с одной функцией (CreateInstance),есть примеры на C++ и Pascal , но я в них ни чего не смыслю.Может кто поможет c переводом на VB6.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Это я пытался переводить варианты на VB6 ни чего не выходит ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Листинг программы
- //////////////////////////// Это пример на С++ - Create cpp. //////////////////////////////////////
- CREATEFUNCPTR CreateInstance;
- HINSTANCE CallCreateInstance(char* name)
- {
- HINSTANCE hCoponent=::LoadLibrary(name);
- if (hComponent==NULL);
- {
- return 0;
- }
- CreateInstance=(CREATEFUNCPTR)::GetProcAddress(hComponent,"CreateInstance");
- if (CreateInstance==NULL)
- {
- return 0;
- }
- return 1;
- }
- /////////////////////////////////// Это реализация //////////////////////////////////////
- ULONG slot =0;
- trace("Get IUnknown pointer");
- CallCreateInstance("lcomp.dll");
- LUnknown* pIUnknown=CreateInstance(slot);
- if (pIUnknown ==NULL) {trace("CallCreateIstance failed") ; return 1;)
- trace("Get IdaqLDevice interface")
- IdaqLDevice* pI;
- HRESULT hr=pIUnknown->QueryInterface(IID_ILDEV,(void**)&pI);
- if (! SUCCEDED(hr)) {trace("Get IdaqLDevice failed"); return 1;}
- trace ("IdaqLDevice get success");
- trace("Free IUnknown");
- pIUnknown->Release();
- pI->OpenLDevice();
- pI->LoadBios("XXX");
- pI->CloseLDevice();
- pI->Release();
- ///////////////////////////////// Базовый Класс Lunknown /////////////////////////////////////////////
- struct LUnknown
- {
- IFC(HRESULT) QueryInterface(const IID& iid,void** ppv)=0;
- IFC(ULONG) AddRef()=0;
- IFC(ULONG) Release()=0
- };
- /////////////////////////////////// Основной интерфейс ////////////////////////////////////////////////
- struct IdaqLDevice
- {
- IFC(HANDLE) OpenLDevice()=0;
- IFC(ULONG) LoadBios(char* FileName)=0;
- }
Листинг программы
- ///////////////////////////////// Это пример на Pascal ////////////////////////////
- unit Create;
- interface
- type
- TCreateInstance=function(slot:ULONG):LUnknown;cdecl;
- var
- hModule:THandle;
- CreateInstance:TCreateInstance;
- function CallCreateInstance(name:PChar):ULONG;
- implementation
- function CallCreateInstance(name:PChar):ULONG;
- begin
- hModule:=0;
- hModule:=LoadLibrary(name);
- if(hModule=0) then
- begin
- Result:=0;
- Exit:
- end;
- @CreateInstance:=GetProcAddress(hModule,'CreateInstance')
- if (@CreateInstance=nil) then
- begin
- Result:=o;
- Exit;
- end;
- Result:=0;
- end;
- end.
- var
- pLDEV :IdaqLDevice;
- pIUnknown : LUnknown;
- hr : integer;
- dev : THandle;
- if (CallCreateInstance('lcomp.dll')=1) then
- begin
- //{OK}
- end;
- pIUnknown:=CreateInstance(slot);
- hr:=pIUnknown.QueryInterface(IID_ILDEV,pLDEV);
- if(not Succeeded(hr)) then MessageBox(0,'Get interface failed','Error');
- pIUnknown.Release;
- dev:=pLDEV.OpenLDevice
- pLDEV.Release
- //////////////////////////////////////////////
- unit ifc;
- interface
- const
- IID_ILDEV : TGUID='{32bb8320-b41b-11cf-a6bb-0080c7b2d682}'
- IID_ILDEV2 : TGUID='{c737c7ef-ecc2-49f2-ba4e-94c889f07399}'
- type
- LUnknown=class
- function QueryInterface(const iid:TGUID;out ppv):HRESULT;virtual;stdcall;abstract;
- function AddRef:ULONG;virtual;stdcall;abstract;
- function Release:ULONG;vitrual;stdcall;abstract;
- end;
- type
- idaqLDevice=class(LUnknown)
- function OpenLDevice : Thandle;virtual;stdcall;abstract;
- function LoadBios(File : PAnsPcar)ULING
- end;
- implementation
- end.
Листинг программы
- Option Explicit
- public type GUID
- data1 as long
- data2 as integer
- data3 as integer
- data4(7) as byte
- end type
- public const IID_ILDEV as GUID = "{32bb8320-b41b-11cf-a6bb-0080c7b2d682}"
- public const IID_ILDEV2 as GUID = "{c737c7ef-ecc2-49f2-ba4e-94c889f07399}"
- public type LUnknonw
- QueryInterface() as long
- AddRef() as long
- Release() as long
- end type
- public const slot as long = 0
- public hModule as long
- public CreateInstance as long
- public pIUnknown as LUnknown
- public declare function LoadLibrary lib "kernel.dll" Alias LoadLibraryA (Byval loLibfileName as string) as long
- public declare function GetProcAddress lib "kernel.dll"(Byval hModule as long,Byval lpProcName as string) as long
- public function CreateInstance(ByVal slot as long) as LUnknown : end function ''
- public function CallCreateInstance(ByVal name as String) as LONG
- hModule = 0
- hModule = LoadLibrary("lcomp.dll")
- if hModule <> 0 then
- Form1.text1.text = HEX(hModule)
- else
- Fomr1.text1.text="Lib Error"
- End if
- CreateInstance=GetProcAddress(hModule,"CreateInstance")''
- if CreateInstance <> 0 then
- Form1.text2.text = HEX(CreateInstance)
- else
- Form1.text2.text = "Func Error"
- end if
- end function
Решение задачи: «Подключение lcomp.dll»
textual
Листинг программы
- dim hLib as long
- dim slot as long
- dim Err as long
- dim pI as Idaqldevice'' пишет "несовподение типов"пробывал разние типы данных для pI и Idaqldevice,ни как.
- hLib=LoadAPIDLL("lcomp.dll")
- pI=CallCreateInstance(hLib,slot,Err)'' в pI восьмизначное dec. число , в Err сообщение об успешной загрузки
- public type Idaqldevice'' базовый класс
- openldevice() as long
- loadbios() as long
- ''разные функции
- end type
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д