Delphi DLL / VB app
- From: "DanG" <dang57@xxxxxxxxxxx>
- Date: 23 Apr 2005 19:33:43 -0700
Getting frustrated here. There has to be a way to do this...
I need to create a DLL that will be called from a VB package. I can
not change the package, so all I can do is attempt to follow the
instructions. (There is no SDK.) Those instructions say to create a
COM object with VB, have a function called 'Process' that accepts
reference to a Class, and returns a Boolean. Unfortunately, I don't
have VB. I only have Delphi 6. So I used Delphi to create an ActiveX
DLL with a COM object, etc. When I run the VB app, I get an error
indicating that it was unable to create the COM object.
Well, I do have MS Access. So I made myself a little form with a
button. When the button is clicked, it does a
CreateObject("<dllname>.<classname>"), and then a call to
Process(Class). The DLL runs perfectly.
Notes:
-Other than "Process := true", all code was generated by the
ActiveX, COM object and Type Library wizards.
-The VB app uses an entry in the registry to be informed of the DLL and
class. The format of that is also <dllname>.<classname>, which is the
same text as I used in the Access CreateObject statement. I expected
that the VB app would use that string to do a CreateObject call, but
perhaps not. The error does indicate the correct name of the
dll/class, so I know it's getting it from the registry successfully.
-The parameter on the Process function (below) is just my last version
of the test. I've tried BStr, IDispatch, and everything else I can
think of. Doesn't work. I don't really think it's a problem
with the parameter, though. If the error is on the Create statement,
then it's not even gotten to the Process call yet.
So, what could the VB app be doing differently than the Access code?
What can I do to make this work?
{Delphi code}
type
TmyCode = class(TTypedComObject, ImyCode)
protected
function Process(const myInput: WideString): WordBool; stdcall;
end;
implementation
uses ComServ;
function TmyCode.Process(const myInput: WideString): WordBool;
begin
Process := true;
end;
initialization
TTypedComObjectFactory.Create(ComServer, TmyCode, Class_myCode,
ciMultiInstance, tmApartment);
end.
{TLB}
ImyCode = interface;
myCode = ImyCode;
ImyCode = interface(IUnknown)
['{6ACB9CC3-453F-451D-BF88-DE60EE836A62}']
function Process(const myInput: WideString): WordBool; stdcall;
end;
ComyCode = class
class function Create: ImyCode;
class function CreateRemote(const MachineName: string): ImyCode;
end;
implementation
uses ComObj;
class function ComyCode.Create: ImyCode;
begin
Result := CreateComObject(CLASS_myCode) as ImyCode;
end;
class function ComyCode.CreateRemote(const MachineName: string):
ImyCode;
begin
Result := CreateRemoteComObject(MachineName, CLASS_myCode) as
ImyCode;
end;
end.
Thanks
Dan
.
- Follow-Ups:
- Re: Delphi DLL / VB app
- From: Markku Nevalainen
- Re: Delphi DLL / VB app
- Prev by Date: Re: windows registered user name
- Next by Date: Re: Delphi DLL / VB app
- Previous by thread: windows registered user name
- Next by thread: Re: Delphi DLL / VB app
- Index(es):