ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Reference to Custom tlb (https://www.excelbanter.com/excel-programming/293789-vba-reference-custom-tlb.html)

Matthew Wieder

VBA Reference to Custom tlb
 
I have a dll which I generated a tlb for and am referencing that tlb
from VBA in Excel (2003). When I try to create and use any custom
defined typedef, I get a "Variable uses an Automation type not supported
in Visual Basic" on compilation. For example, this from the tlb:

struct tagPageDimension {
LPSTR dimensionName;
LPSTR MemberName;
} PageDimension;

then this line in the VBA causes the error:

Dim oTemp As MyClass.PageDimension

Additionally, on the intellisense, I don't get the members when I then do:
oTemp. (dimensionName and MemberName should come up but don't)

Can anyone help?
thanks!



Wei-Dong Xu [MSFT]

VBA Reference to Custom tlb
 
Hi Matthew,

It will be appreciated you let me know what scneario you are at now: from C++ to VB or from .Net to VB.

If from .Net to VB, I assume you are using C# language and the structure definition may be as below:
public structure PageDimension{
public string dimensionName;
public string MemberName;
}

From the inteoped typelibrary, the definition for this structure is the same to yours:
struct tagPageDimension {
LPSTR dimensionName;
LPSTR MemberName;
} PageDimension;

From my test, in VB, the member of this structure can't be retrieved. However, I'd suggest you can use Class instead of the structure here. This
way, you can get the dimensionName and MemberName in VB after the interop.

Look forward to your confirmation on whether your scenario locates at managed scenario or un-managed scenario! Then we can perform further
research for you on this issue. Expect to your reply!

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.



Matthew Wieder

VBA Reference to Custom tlb
 
It is from .NET (C#).

Wei-Dong XU [MSFT] wrote:
Hi Matthew,

It will be appreciated you let me know what scneario you are at now: from C++ to VB or from .Net to VB.

If from .Net to VB, I assume you are using C# language and the structure definition may be as below:
public structure PageDimension{
public string dimensionName;
public string MemberName;
}

From the inteoped typelibrary, the definition for this structure is the same to yours:
struct tagPageDimension {
LPSTR dimensionName;
LPSTR MemberName;
} PageDimension;

From my test, in VB, the member of this structure can't be retrieved. However, I'd suggest you can use Class instead of the structure here. This
way, you can get the dimensionName and MemberName in VB after the interop.

Look forward to your confirmation on whether your scenario locates at managed scenario or un-managed scenario! Then we can perform further
research for you on this issue. Expect to your reply!

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.




Wei-Dong Xu [MSFT]

VBA Reference to Custom tlb
 
Hi Matthew,

From my research, VB doesn't support struct*. It supports BSTR type for the string.

So I'd suggest please change the codes as this in the C# component:

public struct PageDimension
{

[MarshalAs(UnmanagedType.BStr)]
public string dimensionName;

[MarshalAs(UnmanagedType.BStr)]
public string MemberName;
}

Then, tlbexp the assembly to generate the TLB. In my case,
Tlbexp StructInterop.dll /out:mystruct.tlb

In the VB6 side, do this:

Dim myStruct As StructInterop.PageDimension

myStruct.dimensionName = ¡°test¡±
myStruct.MemberName = ¡°this¡±

It works very well!

Please feel free to let me know if you have any further questions.

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.




All times are GMT +1. The time now is 05:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com