VBA Reference to Custom tlb

  • Thread starter Thread starter Matthew Wieder
  • Start date Start date
M

Matthew Wieder

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!
 
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.
 
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.
 
Back
Top