 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Khai Trinh Guest
|
Posted: Tue Jan 25, 2005 7:34 pm Post subject: Using VB.Net DLL in Borland 5.0 |
|
|
I have a DLL that was developed in VB.NET. How can I use this in Borland C++ Builder 5.0?
When I had a DLL developed in VB6.0, I can register it using regsvr32 and then do Import Type Library under Project in Builder 5.0 to use it.
Thanks,
Khai Trinh
|
|
| Back to top |
|
 |
Mike King Guest
|
Posted: Tue Jan 25, 2005 7:56 pm Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
"Khai Trinh" <khai.trinh1 (AT) navy (DOT) mil> wrote
| Quote: |
I have a DLL that was developed in VB.NET. How can I use this in Borland
C++ Builder 5.0?
When I had a DLL developed in VB6.0, I can register it using regsvr32 and
then do Import Type Library under Project in Builder 5.0 to use it.
Thanks,
Khai Trinh
|
Take a look at this link
([url]http://www.codeproject.com/dotnet/cominterop.asp#GenTLB)[/url]. It mentions a
tool that allows you to create a TLB file from a assembly, which you can
import using the "Import Type Library" tool in BCB.
|
|
| Back to top |
|
 |
Khai Trinh Guest
|
Posted: Wed Jan 26, 2005 1:11 am Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
Thanks,
Now I can register and import the type library. After I
installed the package, I tried to use the components but I
cannot see the methods or functions that were in VB.Net.
I can see functions like "GetDefaultInterface", "Connect",
"MethodName". I tried playing with these but didn't get
any where. What else do I need to do in order to use the
functions that were in VB.Net?
Thank you,
Khai Trinh
"Mike King" <emailMK (AT) excite (DOT) com> wrote:
| Quote: | "Khai Trinh" <khai.trinh1 (AT) navy (DOT) mil> wrote in message
news:41f69f5f$1 (AT) newsgroups (DOT) borland.com...
I have a DLL that was developed in VB.NET. How can I use this in Borland
C++ Builder 5.0?
When I had a DLL developed in VB6.0, I can register it using regsvr32 and
then do Import Type Library under Project in Builder 5.0 to use it.
Thanks,
Khai Trinh
Take a look at this link
([url]http://www.codeproject.com/dotnet/cominterop.asp#GenTLB)[/url]. It mentions a
tool that allows you to create a TLB file from a assembly, which you can
import using the "Import Type Library" tool in BCB.
|
|
|
| Back to top |
|
 |
Mike King Guest
|
Posted: Wed Jan 26, 2005 1:58 pm Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
"Khai Trinh" <khai.trinh1 (AT) navy (DOT) mil> wrote
| Quote: |
Thanks,
Now I can register and import the type library. After I
installed the package, I tried to use the components but I
cannot see the methods or functions that were in VB.Net.
I can see functions like "GetDefaultInterface", "Connect",
"MethodName". I tried playing with these but didn't get
any where. What else do I need to do in order to use the
functions that were in VB.Net?
Thank you,
Khai Trinh
|
Can you post the definition of the class you are trying to use. It sounds
like the class you are trying to use is derived from TOleServer.
|
|
| Back to top |
|
 |
Khai Trinh Guest
|
Posted: Wed Jan 26, 2005 2:47 pm Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
| Quote: | Can you post the definition of the class you are trying to use. It sounds
like the class you are trying to use is derived from TOleServer.
|
Below is a section from my WSWrapper4SMEPS_tlb.h file. I hope
this is what you are looking for. Thanks alot for helping.
// ************************************************************************ //
// C++ TLBWRTR : $Revision: 1.134.1.41 $
// File generated on 25-Jan-2005 4:58:01 PM from Type Library described below.
// ************************************************************************ //
// Type Lib: c:testryan.tlb (1)
// IIDLCID: {C1DA7E84-5A86-4AD4-8BD6-88374305C783}
// Helpfile:
// DepndLst:
// (1) v1.10 mscorlib, (C:WINNTMicrosoft.NETFrameworkv1.1.4322mscorlib.tlb)
// (2) v1.10 System, (C:WINNTMicrosoft.NETFrameworkv1.1.4322System.tlb)
// (3) v2.0 stdole, (C:WINNTsystem32stdole2.tlb)
// (4) v4.0 StdVCL, (C:WINNTsystem32STDVCL40.DLL)
// ************************************************************************ //
#ifndef __WSWrapper4SMEPS_TLB_h__
#define __WSWrapper4SMEPS_TLB_h__
#pragma option push -b -w-inl
#include <utilcls.h>
#if !defined(__UTILCLS_H_VERSION) || (__UTILCLS_H_VERSION < 0x0500)
//
// The code generated by the TLIBIMP utility or the Import|TypeLibrary
// and Import|ActiveX feature of C++Builder rely on specific versions of
// the header file UTILCLS.H found in the INCLUDEVCL directory. If an
// older version of the file is detected, you probably need an update/patch.
//
#error "This file requires a newer version of the header UTILCLS.H"
"You need to apply an update/patch to your copy of C++Builder"
#endif
#include
#include <ocidl.h>
#if defined(USING_ATLVCL) || defined(USING_ATL)
#if !defined(__TLB_NO_EVENT_WRAPPERS)
#include <atl/atlmod.h>
#endif
#endif
#include "mscorlib_TLB.h"
#include "System_TLB.h"
// *********************************************************************//
// Forward reference of some VCL types (to avoid including STDVCL.HPP)
// *********************************************************************//
namespace Stdvcl {class IStrings; class IStringsDisp;}
using namespace Stdvcl;
typedef TComInterface<IStrings> IStringsPtr;
typedef TComInterface<IStringsDisp> IStringsDispPtr;
namespace Wswrapper4smeps_tlb
{
// *********************************************************************//
// HelpString:
// Version: 1.0
// *********************************************************************//
// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:
// Type Libraries : LIBID_xxxx
// CoClasses : CLSID_xxxx
// DISPInterfaces : DIID_xxxx
// Non-DISP interfaces: IID_xxxx
// *********************************************************************//
extern __declspec (package) const GUID LIBID_WSWrapper4SMEPS;
extern __declspec (package) const GUID IID__SmsPPR;
extern __declspec (package) const GUID IID__GetDetailPPR4SMEPS;
extern __declspec (package) const GUID IID__GetPKI;
extern __declspec (package) const GUID IID__GetPPRList4SMEPS;
extern __declspec (package) const GUID IID__TestAddTwoNumbers;
extern __declspec (package) const GUID CLSID_SmsPPR;
extern __declspec (package) const GUID CLSID_GetDetailPPR4SMEPS;
extern __declspec (package) const GUID CLSID_GetPKI;
extern __declspec (package) const GUID CLSID_GetPPRList4SMEPS;
extern __declspec (package) const GUID CLSID_TestAddTwoNumbers;
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
interface DECLSPEC_UUID("{5BE73D1E-D2A2-3B19-8997-0AF2944320A9}") _SmsPPR;
typedef TComInterface<_SmsPPR, &IID__SmsPPR> _SmsPPRPtr;
interface DECLSPEC_UUID("{8F608210-90A2-3BE1-834A-A893CCD44741}") _GetDetailPPR4SMEPS;
typedef TComInterface<_GetDetailPPR4SMEPS, &IID__GetDetailPPR4SMEPS> _GetDetailPPR4SMEPSPtr;
interface DECLSPEC_UUID("{38C1F4A1-9D47-35DB-8F0D-86391483893A}") _GetPKI;
typedef TComInterface<_GetPKI, &IID__GetPKI> _GetPKIPtr;
interface DECLSPEC_UUID("{4E0C485B-4EE5-379D-BDF3-D09D192B04C2}") _GetPPRList4SMEPS;
typedef TComInterface<_GetPPRList4SMEPS, &IID__GetPPRList4SMEPS> _GetPPRList4SMEPSPtr;
interface DECLSPEC_UUID("{C2430EF6-0112-3615-A5C9-59B3A1F86F5D}") _TestAddTwoNumbers;
typedef TComInterface<_TestAddTwoNumbers, &IID__TestAddTwoNumbers> _TestAddTwoNumbersPtr;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
//
// The LIBID_OF_ macro(s) map a LIBID_OF_CoClassName to the GUID of this
// TypeLibrary. It simplifies the updating of macros when CoClass name
// change.
// *********************************************************************//
typedef _SmsPPR SmsPPR;
typedef _SmsPPRPtr SmsPPRPtr;
typedef _GetDetailPPR4SMEPS GetDetailPPR4SMEPS;
typedef _GetDetailPPR4SMEPSPtr GetDetailPPR4SMEPSPtr;
typedef _GetPKI GetPKI;
typedef _GetPKIPtr GetPKIPtr;
typedef _GetPPRList4SMEPS GetPPRList4SMEPS;
typedef _GetPPRList4SMEPSPtr GetPPRList4SMEPSPtr;
typedef _TestAddTwoNumbers TestAddTwoNumbers;
typedef _TestAddTwoNumbersPtr TestAddTwoNumbersPtr;
#define LIBID_OF_SmsPPR (&LIBID_WSWrapper4SMEPS)
#define LIBID_OF_GetDetailPPR4SMEPS (&LIBID_WSWrapper4SMEPS)
#define LIBID_OF_GetPKI (&LIBID_WSWrapper4SMEPS)
#define LIBID_OF_GetPPRList4SMEPS (&LIBID_WSWrapper4SMEPS)
#define LIBID_OF_TestAddTwoNumbers (&LIBID_WSWrapper4SMEPS)
// *********************************************************************//
// Interface: _SmsPPR
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {5BE73D1E-D2A2-3B19-8997-0AF2944320A9}
// *********************************************************************//
interface _SmsPPR : public IDispatch
{
public:
#if !defined(__TLB_NO_INTERFACE_WRAPPERS)
#endif // __TLB_NO_INTERFACE_WRAPPERS
};
// *********************************************************************//
// Interface: _GetDetailPPR4SMEPS
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {8F608210-90A2-3BE1-834A-A893CCD44741}
// *********************************************************************//
interface _GetDetailPPR4SMEPS : public IDispatch
{
public:
#if !defined(__TLB_NO_INTERFACE_WRAPPERS)
#endif // __TLB_NO_INTERFACE_WRAPPERS
};
// *********************************************************************//
// Interface: _GetPKI
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {38C1F4A1-9D47-35DB-8F0D-86391483893A}
// *********************************************************************//
interface _GetPKI : public IDispatch
{
public:
#if !defined(__TLB_NO_INTERFACE_WRAPPERS)
#endif // __TLB_NO_INTERFACE_WRAPPERS
};
// *********************************************************************//
// Interface: _GetPPRList4SMEPS
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {4E0C485B-4EE5-379D-BDF3-D09D192B04C2}
// *********************************************************************//
interface _GetPPRList4SMEPS : public IDispatch
{
public:
#if !defined(__TLB_NO_INTERFACE_WRAPPERS)
#endif // __TLB_NO_INTERFACE_WRAPPERS
};
// *********************************************************************//
// Interface: _TestAddTwoNumbers
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {C2430EF6-0112-3615-A5C9-59B3A1F86F5D}
// *********************************************************************//
interface _TestAddTwoNumbers : public IDispatch
{
public:
#if !defined(__TLB_NO_INTERFACE_WRAPPERS)
#endif // __TLB_NO_INTERFACE_WRAPPERS
};
#if !defined(__TLB_NO_INTERFACE_WRAPPERS)
// *********************************************************************//
// SmartIntf: TCOM_SmsPPR
// Interface: _SmsPPR
// *********************************************************************//
template <class T /* _SmsPPR */ >
class TCOM_SmsPPRT : public TComInterface<_SmsPPR>, public TComInterfaceBase<IUnknown>
{
public:
TCOM_SmsPPRT() {}
TCOM_SmsPPRT(_SmsPPR *intf, bool addRef = false) : TComInterface<_SmsPPR>(intf, addRef) {}
TCOM_SmsPPRT(const TCOM_SmsPPRT& src) : TComInterface<_SmsPPR>(src) {}
TCOM_SmsPPRT& operator=(const TCOM_SmsPPRT& src) { Bind(src, true); return *this;}
};
typedef TCOM_SmsPPRT<_SmsPPR> TCOM_SmsPPR;
// *********************************************************************//
// DispIntf: _SmsPPR
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {5BE73D1E-D2A2-3B19-8997-0AF2944320A9}
// *********************************************************************//
template<class T>
class _SmsPPRDispT : public TAutoDriver<_SmsPPR>
{
public:
_SmsPPRDispT(){}
_SmsPPRDispT(_SmsPPR *pintf)
{
TAutoDriver<_SmsPPR>::Bind(pintf, false);
}
_SmsPPRDispT(_SmsPPRPtr pintf)
{
TAutoDriver<_SmsPPR>::Bind(pintf, true);
}
_SmsPPRDispT& operator=(_SmsPPR *pintf)
{
TAutoDriver<_SmsPPR>::Bind(pintf, false);
return *this;
}
_SmsPPRDispT& operator=(_SmsPPRPtr pintf)
{
TAutoDriver<_SmsPPR>::Bind(pintf, true);
return *this;
}
HRESULT BindDefault()
{
return OLECHECK(Bind(CLSID_SmsPPR));
}
HRESULT BindRunning()
{
return BindToActive(CLSID_SmsPPR);
}
};
typedef _SmsPPRDispT<_SmsPPR> _SmsPPRDisp;
// *********************************************************************//
// SmartIntf: TCOM_GetDetailPPR4SMEPS
// Interface: _GetDetailPPR4SMEPS
// *********************************************************************//
template <class T /* _GetDetailPPR4SMEPS */ >
class TCOM_GetDetailPPR4SMEPST : public TComInterface<_GetDetailPPR4SMEPS>, public TComInterfaceBase<IUnknown>
{
public:
TCOM_GetDetailPPR4SMEPST() {}
TCOM_GetDetailPPR4SMEPST(_GetDetailPPR4SMEPS *intf, bool addRef = false) : TComInterface<_GetDetailPPR4SMEPS>(intf, addRef) {}
TCOM_GetDetailPPR4SMEPST(const TCOM_GetDetailPPR4SMEPST& src) : TComInterface<_GetDetailPPR4SMEPS>(src) {}
TCOM_GetDetailPPR4SMEPST& operator=(const TCOM_GetDetailPPR4SMEPST& src) { Bind(src, true); return *this;}
};
typedef TCOM_GetDetailPPR4SMEPST<_GetDetailPPR4SMEPS> TCOM_GetDetailPPR4SMEPS;
// *********************************************************************//
// DispIntf: _GetDetailPPR4SMEPS
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {8F608210-90A2-3BE1-834A-A893CCD44741}
// *********************************************************************//
template<class T>
class _GetDetailPPR4SMEPSDispT : public TAutoDriver<_GetDetailPPR4SMEPS>
{
public:
_GetDetailPPR4SMEPSDispT(){}
_GetDetailPPR4SMEPSDispT(_GetDetailPPR4SMEPS *pintf)
{
TAutoDriver<_GetDetailPPR4SMEPS>::Bind(pintf, false);
}
_GetDetailPPR4SMEPSDispT(_GetDetailPPR4SMEPSPtr pintf)
{
TAutoDriver<_GetDetailPPR4SMEPS>::Bind(pintf, true);
}
_GetDetailPPR4SMEPSDispT& operator=(_GetDetailPPR4SMEPS *pintf)
{
TAutoDriver<_GetDetailPPR4SMEPS>::Bind(pintf, false);
return *this;
}
_GetDetailPPR4SMEPSDispT& operator=(_GetDetailPPR4SMEPSPtr pintf)
{
TAutoDriver<_GetDetailPPR4SMEPS>::Bind(pintf, true);
return *this;
}
HRESULT BindDefault()
{
return OLECHECK(Bind(CLSID_GetDetailPPR4SMEPS));
}
HRESULT BindRunning()
{
return BindToActive(CLSID_GetDetailPPR4SMEPS);
}
};
typedef _GetDetailPPR4SMEPSDispT<_GetDetailPPR4SMEPS> _GetDetailPPR4SMEPSDisp;
|
|
| Back to top |
|
 |
Mike King Guest
|
Posted: Wed Jan 26, 2005 3:17 pm Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
"Khai Trinh" <khai.trinh1 (AT) navy (DOT) mil> wrote
| Quote: |
Can you post the definition of the class you are trying to use. It sounds
like the class you are trying to use is derived from TOleServer.
Below is a section from my WSWrapper4SMEPS_tlb.h file. I hope
this is what you are looking for. Thanks alot for helping.
...
|
It looks like the "Import Type Library" tool didn't find any callable
functions on the different types in your assembly. This is unknown
territory for me. Make sure you have at least one public function on the
types that are in your assembly.
|
|
| Back to top |
|
 |
Khai Trinh Guest
|
Posted: Wed Jan 26, 2005 3:43 pm Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
| Quote: | It looks like the "Import Type Library" tool didn't find any callable
functions on the different types in your assembly. This is unknown
territory for me. Make sure you have at least one public function on the
types that are in your assembly.
|
I'm sure that the functions are made public. In the WSWrapper4SMEPS_tlb.h file there was this:
#if !defined(__UTILCLS_H_VERSION) || (__UTILCLS_H_VERSION < 0x0500)
//
// The code generated by the TLIBIMP utility or the Import|TypeLibrary
// and Import|ActiveX feature of C++Builder rely on specific versions of
// the header file UTILCLS.H found in the INCLUDEVCL directory. If an
// older version of the file is detected, you probably need an update/patch.
//
#error "This file requires a newer version of the header UTILCLS.H"
"You need to apply an update/patch to your copy of C++Builder"
#endif
Do you think this could be the cause? I am looking for the latest UTILCLS.H from Borland for C++Builder 5.0.
Thanks,
Khai
|
|
| Back to top |
|
 |
Mike King Guest
|
Posted: Wed Jan 26, 2005 5:32 pm Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
| Quote: | I'm sure that the functions are made public. In the WSWrapper4SMEPS_tlb.h
file there was this:
#if !defined(__UTILCLS_H_VERSION) || (__UTILCLS_H_VERSION < 0x0500)
//
// The code generated by the TLIBIMP utility or the Import|TypeLibrary
// and Import|ActiveX feature of C++Builder rely on specific versions of
// the header file UTILCLS.H found in the INCLUDEVCL directory. If an
// older version of the file is detected, you probably need an
update/patch.
//
#error "This file requires a newer version of the header UTILCLS.H"
"You need to apply an update/patch to your copy of C++Builder"
#endif
Do you think this could be the cause? I am looking for the latest
UTILCLS.H from Borland for C++Builder 5.0.
Thanks,
Khai
|
I don't think that is the cause. I think it says that because it includes
it. The tool itself doesn't rely on utilcls.h, but the code it generates
does.
It looks like the Tlbexp tool does not export the available functions, but
you can still call them. To do this, create an instance of the class like
you normally would and get the interface you want. Now, create a Variant
instance and pass it the COM interface. The Variant class has functions
like OleFunction, OlePropertyGet and OlePropertySet. Use these functions to
access the VB.NET classes.
I think this should work because I created a sample application to test my
theory. I made a VB6 application that references the mscorlib.tlb file. I
place a button on the form that has the code shown below, and it worked.
This tells me that you can only late-bind to the functions and properties on
..NET classes.
Private Sub Command1_Click()
Dim mike As New Stack
mike.Push "a"
mike.Push "b"
Debug.Print mike.Pop
Debug.Print mike.Pop
End Sub
|
|
| Back to top |
|
 |
Khai Trinh Guest
|
Posted: Thu Jan 27, 2005 6:38 am Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
| Quote: | It looks like the Tlbexp tool does not export the available functions, but
you can still call them. To do this, create an instance of the class like
you normally would and get the interface you want. Now, create a Variant
instance and pass it the COM interface. The Variant class has functions
like OleFunction, OlePropertyGet and OlePropertySet. Use these functions to
access the VB.NET classes.
I think this should work because I created a sample application to test my
theory. I made a VB6 application that references the mscorlib.tlb file. I
place a button on the form that has the code shown below, and it worked.
This tells me that you can only late-bind to the functions and properties on
.NET classes.
Private Sub Command1_Click()
Dim mike As New Stack
mike.Push "a"
mike.Push "b"
Debug.Print mike.Pop
Debug.Print mike.Pop
End Sub
|
Mike,
Can you please give me some code examples on how to call the function in Builder 5? I can't figure it out.
Thanks,
Khai
|
|
| Back to top |
|
 |
Mike King Guest
|
Posted: Thu Jan 27, 2005 2:59 pm Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
| Quote: | Mike,
Can you please give me some code examples on how to call the function in
Builder 5? I can't figure it out.
Thanks,
Khai
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <iostream>
#include <utilcls.h>
using namespace std;
//---------------------------------------------------------------------------
const GUID CLSID_Stack = {0x4599202D, 0x460F, 0x3FB7,
{0x8A,0x1C,0xC2,0xCC,0x6E,0xD6,0xC7,0xC8} };
#pragma argsused
int main(int argc, char* argv[])
{
CoInitialize(NULL); // Starts the COM Subsystem
TComInterface<IDispatch> StackDispatchPtr; // IDispatch wrapper
Variant StackVariant; // A Variant which is going
to hold a reference
// to a Stack interface.
CoClassCreator::CoCreateInstance(CLSID_Stack,
IID_IDispatch,
(void**) &StackDispatchPtr); // Create
Stack instance
StackVariant = (IDispatch*) StackDispatchPtr; // Give the interface to a
Variant because it mades
// it easy to call
functions.
StackVariant.OleFunction("Push", "1");
StackVariant.OleFunction("Push", "2");
cout << AnsiString(StackVariant.OleFunction("Pop")).c_str() << endl;
cout << AnsiString(StackVariant.OleFunction("Pop")).c_str() << endl;
StackDispatchPtr.Release(); // Release the interface
CoUninitialize(); // Stops the COM Subsystem
return 0;
}
//---------------------------------------------------------------------------
|
|
| Back to top |
|
 |
Khai Trinh Guest
|
Posted: Fri Jan 28, 2005 11:47 pm Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
"Mike King" <emailMK (AT) excite (DOT) com> wrote:
| Quote: | Mike,
Can you please give me some code examples on how to call the function in
Builder 5? I can't figure it out.
Thanks,
Khai
//---------------------------------------------------------------------------
#include <vcl.h
#pragma hdrstop
#include
#include
using namespace std;
//---------------------------------------------------------------------------
const GUID CLSID_Stack = {0x4599202D, 0x460F, 0x3FB7,
{0x8A,0x1C,0xC2,0xCC,0x6E,0xD6,0xC7,0xC8} };
#pragma argsused
int main(int argc, char* argv[])
{
CoInitialize(NULL); // Starts the COM Subsystem
TComInterface
Variant StackVariant; // A Variant which is going
to hold a reference
// to a Stack interface.
CoClassCreator::CoCreateInstance(CLSID_Stack,
IID_IDispatch,
(void**) &StackDispatchPtr); // Create
Stack instance
StackVariant = (IDispatch*) StackDispatchPtr; // Give the interface to a
Variant because it mades
// it easy to call
functions.
StackVariant.OleFunction("Push", "1");
StackVariant.OleFunction("Push", "2");
cout << AnsiString(StackVariant.OleFunction("Pop")).c_str() << endl;
cout << AnsiString(StackVariant.OleFunction("Pop")).c_str() << endl;
StackDispatchPtr.Release(); // Release the interface
CoUninitialize(); // Stops the COM Subsystem
return 0;
}
//---------------------------------------------------------------------------
Thanks, your recommendation works. I also found out that if I turn "Intellisense" on in my VB.Net code, then I can see the methods in my component when I install it in Borland Builder 5. |
In my VB code I added this:
Imports System.Runtime.InteropServices
This works fine for methods that don't reference Microsoft.web.services2.dll. However, On methods that reference microsoft.web.services2.dll I get an EOleSysError exception. Please help me fix this. I tried registering the web.services2.dll and installing it in Builder 5 without any luck. Thank you for all your help.
Khai
|
|
| Back to top |
|
 |
Mike King Guest
|
Posted: Mon Jan 31, 2005 4:23 pm Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
| Quote: | Thanks, your recommendation works. I also found out that if I turn
"Intellisense" on in my VB.Net code, then I can see the methods in my
component when I install it in Borland Builder 5.
In my VB code I added this:
Imports System.Runtime.InteropServices
ClassInterface(ClassInterfaceType.AutoDual)> Public Class ....
This works fine for methods that don't reference
Microsoft.web.services2.dll. However, On methods that reference
microsoft.web.services2.dll I get an EOleSysError exception. Please help
me fix this. I tried registering the web.services2.dll and installing it
in Builder 5 without any luck. Thank you for all your help.
Khai
|
I don't understand your first comment about turning on "Intellisence" and
how it affected Builder.
Now, about the exception... The error is occurring because the
"microsoft.web.services2.dll" assembly isn't loaded into the AppDomain that
your class is using. I don't know the proper way to get it to load into the
AppDomain, but I do know of a work-around. On the Assembly class, there is
a LoadFrom function, which loads an assembly from the filename passed in.
Take a look at the following C# code and the corresponding C++ code.
using System;
using System.Xml;
namespace dotNETtoCOM
{
public class Test
{
public int Add(int a, int b)
{
return a + b;
}
public string GetXml ( )
{
System.Reflection.Assembly.LoadFrom(@"C:WINDOWSMicrosoft.NETFrameworkv1.1.4322System.XML.dll");
XmlDocument dom = new XmlDocument();
dom.LoadXml("<?xml version="1.0"?>n<root />");
return dom.OuterXml;
}
}
}
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <iostream>
#include <utilcls.h>
using namespace std;
//---------------------------------------------------------------------------
const GUID CLSID_Stack = {0x4599202D, 0x460F, 0x3FB7,
{0x8A,0x1C,0xC2,0xCC,0x6E,0xD6,0xC7,0xC8} };
const GUID CLSID_dotNETtoCOM = {0x538B715A, 0xFDC1, 0x3D61,
{0xB7,0xC4,0x9B,0xFD,0x27,0xC2,0x9E,0xC2} };
void Test ( );
#pragma argsused
int main(int argc, char* argv[])
{
CoInitialize(NULL); // Starts the COM Subsystem
TComInterface<IDispatch> StackDispatchPtr; // IDispatch wrapper
Variant StackVariant; // A Variant which is going
to hold a reference
// to a Stack interface.
CoClassCreator::CoCreateInstance(CLSID_Stack,
IID_IDispatch,
(void**) &StackDispatchPtr); // Create
Stack instance
StackVariant = (IDispatch*) StackDispatchPtr; // Give the interface to a
Variant because it mades
// it easy to call
functions.
StackVariant.OleFunction("Push", "1");
StackVariant.OleFunction("Push", "2");
cout << AnsiString(StackVariant.OleFunction("Pop")).c_str() << endl;
cout << AnsiString(StackVariant.OleFunction("Pop")).c_str() << endl;
StackDispatchPtr.Release(); // Release the interface
Test();
CoUninitialize(); // Stops the COM Subsystem
return 0;
}
//---------------------------------------------------------------------------
void Test ( )
{
TComInterface
Variant TestVariant;
CoClassCreator::CoCreateInstance(CLSID_dotNETtoCOM,
IID_IDispatch,
(void**) &TestDispatchPtr);
TestVariant = (IDispatch*) TestDispatchPtr;
cout << AnsiString(TestVariant.OleFunction("Add", 1, 2)).c_str() << endl;
cout << AnsiString(TestVariant.OleFunction("GetXml")).c_str() << endl;
TestDispatchPtr.Release(); // Release the interface
}
//---------------------------------------------------------------------------
|
|
| Back to top |
|
 |
Khai Trinh Guest
|
Posted: Wed Feb 09, 2005 10:31 pm Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
| Quote: | Now, about the exception... The error is occurring because the
"microsoft.web.services2.dll" assembly isn't loaded into the AppDomain that
your class is using.
//---------------------------------------------------------------------------
#include <vcl.h
#pragma hdrstop
#include
#include
using namespace std;
//---------------------------------------------------------------------------
const GUID CLSID_Stack = {0x4599202D, 0x460F, 0x3FB7,
{0x8A,0x1C,0xC2,0xCC,0x6E,0xD6,0xC7,0xC8} };
const GUID CLSID_dotNETtoCOM = {0x538B715A, 0xFDC1, 0x3D61,
{0xB7,0xC4,0x9B,0xFD,0x27,0xC2,0x9E,0xC2} };
void Test ( );
#pragma argsused
int main(int argc, char* argv[])
{
CoInitialize(NULL); // Starts the COM Subsystem
TComInterface
Variant StackVariant; // A Variant which is going
to hold a reference
// to a Stack interface.
CoClassCreator::CoCreateInstance(CLSID_Stack,
IID_IDispatch,
(void**) &StackDispatchPtr); // Create
Stack instance
StackVariant = (IDispatch*) StackDispatchPtr; // Give the interface to a
Variant because it mades
// it easy to call
functions.
StackVariant.OleFunction("Push", "1");
StackVariant.OleFunction("Push", "2");
cout << AnsiString(StackVariant.OleFunction("Pop")).c_str() << endl;
cout << AnsiString(StackVariant.OleFunction("Pop")).c_str() << endl;
StackDispatchPtr.Release(); // Release the interface
Test();
CoUninitialize(); // Stops the COM Subsystem
return 0;
}
//---------------------------------------------------------------------------
void Test ( )
{
TComInterface
Variant TestVariant;
CoClassCreator::CoCreateInstance(CLSID_dotNETtoCOM,
IID_IDispatch,
(void**) &TestDispatchPtr);
TestVariant = (IDispatch*) TestDispatchPtr;
cout << AnsiString(TestVariant.OleFunction("Add", 1, 2)).c_str() << endl;
cout << AnsiString(TestVariant.OleFunction("GetXml")).c_str() << endl;
TestDispatchPtr.Release(); // Release the interface
}
//---------------------------------------------------------------------------
Mike, |
I just came back from my business trip last week and been banging my head on this for the last 2 days. Your explanation
about the microsoft.web.services2.dll is not in the AppDomain
makes sense, but I don't see what's the different between the
way you are doing it in test() and the way you are doing in
main().
In my DLL, I have a function call Add (which doesn't reference
the ...services2.dll) and a function call GetPKI which uses
the ...services2.dll. The Add works fine. The GetPKI function
gives me this error:
this->GetCerfificates((BSTR*)&pRetVal)) Error:80131508
@ c:program fielscbuilder5importswswrapper_tlb.h/191
I really appreciate your help.
Thanks,
Khai
|
|
| Back to top |
|
 |
Mike King Guest
|
Posted: Thu Feb 10, 2005 3:31 pm Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
| Quote: | ... Your explanation
about the microsoft.web.services2.dll not in the AppDomain
makes sense, but I don't see what's the different between the
way you are doing it in test() and the way you are doing in
main().
|
Yes, there is no different between the way I create and call the .NET
objects. The test function calls the GetXml function which is in the .NET
class. Within the GetXml function, a XmlDocument object is created, which
forever reason will not work unless an explicit call is made to load the
System.Xml assembly. That call to load the assembly in done in the C# code.
I have the feeling that this information won't help you. If this is true,
then post some code that I can run to test out the problem. I know
sometimes reducing the code down to a small test case can be time-consuming,
but spending days scratching ones head is as well.
|
|
| Back to top |
|
 |
Khai Trinh Guest
|
Posted: Thu Feb 10, 2005 4:23 pm Post subject: Re: Using VB.Net DLL in Borland 5.0 |
|
|
| Quote: | Yes, there is no different between the way I create and call the .NET
objects. The test function calls the GetXml function which is in the .NET
class. Within the GetXml function, a XmlDocument object is created, which
forever reason will not work unless an explicit call is made to load the
System.Xml assembly. That call to load the assembly in done in the C# code.
I have the feeling that this information won't help you. If this is true,
then post some code that I can run to test out the problem. I know
sometimes reducing the code down to a small test case can be time-consuming,
but spending days scratching ones head is as well.
|
Thanks for turning on my lights! I was trying to load the
System.XML.dll from Builder5 instead of from my .NET . From
what you are telling me, I think once I do this it should work.
Thank you again,
Khai
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|