Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Structure in VB

Posted on 1998-10-09
12
Medium Priority
?
303 Views
Last Modified: 2013-12-26
I have a component (written in VC++6.0 ATL 3.0)
that has a dual interface, and a custom interface.
custom interface has a setparcel method, that takes
a structure (two methods one with value other with reference)
here is a part from idl file

typedef struct tagPocket  
{
      long ID; // here I removed all members but one for simplicity//
} Pocket;

interface IParcelCustom : IUnknown
{
            [helpstring("method SetParcel")] HRESULT SetParcel([in] Pocket parcel);
            [helpstring("method GetParcel")] HRESULT GetParcel([out, retval] Pocket *parcel);
            [helpstring("method SetParcelByRef")] HRESULT SetParcelByRef([in] Pocket *pparcel);
      };

and dual interface has

interface IParcel : IDispatch
{

[id(1), helpstring("method GetID")] HRESULT GetID([out, retval] long* id);
[id(2), helpstring("method GetCustomInterface")] HRESULT GetCustomInterface([out, retval] IParcelCustom** ppObj);
      };
so it can return a custom interface

this works fine from a C++ client.

but from excel VBA I try to convince it that I have the same structure, my vb code is
Dim a As New Parcel
Dim b As IParcelCustom
Private Type tagPocket
    samp_t As Long
End Type

Sub test()
Set b = a.GetCustomInterface
Dim pocket As tagPocket
pocket.samp_t = 30
b.SetParcelByRef (pocket) // here is the compile error
End Sub
it says Type mismatch (Error 13)
so he does not like my structure
although he expects pparcel As tagPocket on the tooltip
as below
b.SetParcelByRef (pparcel As tagPocket)
so how can I convince the compiler that it is what it should be. ??? If I can work this I will
increase the points, nd please do not lock the question
by guessing. just put a command. thanks.
0
Comment
Question by:hasmet
  • 7
  • 4
12 Comments
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1487561
what version are you running?
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1487562
Change the following:

typedef struct Pocket  
{
long ID; // here I removed all members but one for simplicity//
} Pocket;

Dim pocket As Pocket
pocket.samp_t = 30
b.SetParcelByRef (pocket) // here is the compile error

I can mail you a project that shows you how to do structs in VB.
You can also download it at http://www.worldofatl.com/LegalDownload.asp?URL=Downloads/WorksWithVB.zip
(or choose Downloads and topic structs&vb at their home page)
0
 
LVL 1

Author Comment

by:hasmet
ID: 1487563
if you are saying that tagPocket change to Pocket, that did
change anything.

I have VB6.0 AS
Private Type Pocket
    samp_t As Long
End Type
Private Function doit(p As Pocket)
MsgBox p.samp_t
End Function
Private Sub Form_Load()
Dim a As New Parcel
Dim b As IParcelCustom
Set b = a.GetCustomInterface
Dim pparcel As Pocket
pparcel.samp_t = 30
MsgBox pparcel.samp_t
Call doit(pparcel) // WORKS
Call b.SetParcelByRef(pparcel) // DOESNOT WORK
End Sub

and ATL 3.0 (VC++6.0)

IDL has
typedef struct Pocket  
{
      long samp_t;
} Pocket;

if I missed your suggestion, please let me know. I just
wanted to keep question open until It is solved for sure.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 13

Expert Comment

by:Mirkwood
ID: 1487564
Have you downloaded the example I pointed you to?
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1487565
You can do a QueryInterface in VB by just assigning.
So IParcelCustom and IParcel are both interfaces of Parcel then the following would work.

Dim parc as new Parcel
dim parcCustom as IParcelCustom
set parcCustom = parc  ' this does a queryinterface

BTW: Is b valid? debug.assert not b is nothing

0
 
LVL 1

Author Comment

by:hasmet
ID: 1487566
the problem is with the argument, errir is Type mismatch
b is valid, and as I pointed out before,  b.SetParcelByRef(pparcel) he even shows that he expects pparcel As Pocket
exactly same as doit(pparcel). but doit works fine( since
internal) and b.SetParcelByRef(pparcel) fails to compile
gives Type mismatch error, that is odd. If you like
I can mail you a very simple ATL component, VC++ client,
and VB client. so problem is with argument as structure,
if it is just a long type, it works fine, some how structure
fails in type checking. b is valid.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1487567
Mail it to mirkwood23@hotmail.com
or ICQ 5982016
0
 
LVL 1

Author Comment

by:hasmet
ID: 1487568
this question is reserved for mirkwood to get his points.
if you have a good way to somehow load the struct info
to Excel VBA, I can open a new question for a new answer.
thanks
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1487569
Here is and example on how to create a module using IDL
dllname should point to your dll.

      [
            dllname("advapi32.dll"),
            /*uuid(3601a086-06bb-11d2-9f31-008048ec4ce4),*/
            helpstring("ModWin32Reg module")
      ]
      module ModWin32Reg {
            //
            // Predefined Value Types.
            //
            const LONG REG_SZ                    = ( 1 ); // Unicode nul terminated string
            const LONG REG_EXPAND_SZ             = ( 2 ); // Unicode nul terminated string
                                                // (with environment variable references)
            const LONG REG_DWORD                 = ( 4 ); // 32-bit number
            const LONG REG_MULTI_SZ              = ( 7 ); // Multiple Unicode strings

            //
            // Reserved Key Handles.
            //
            const LONG HKEY_CLASSES_ROOT         = (( HKEY ) 0x80000000 );
            const LONG HKEY_CURRENT_USER         = (( HKEY ) 0x80000001 );
            const LONG HKEY_LOCAL_MACHINE        = (( HKEY ) 0x80000002 );
            const LONG HKEY_USERS                = (( HKEY ) 0x80000003 );

            //
            // Error code definitions
            //
            const LONG ERROR_NONE = 0;
            const LONG ERROR_SUCCESS = 0;
            const LONG ERROR_BADDB = 1;
            const LONG ERROR_BADKEY = 2;
            const LONG ERROR_CANTOPEN = 3;
            const LONG ERROR_CANTREAD = 4;
            const LONG ERROR_CANTWRITE = 5;
            const LONG ERROR_OUTOFMEMORY = 6;
            const LONG ERROR_INVALID_PARAMETER = 7;
            const LONG ERROR_ACCESS_DENIED = 8;
            const LONG ERROR_INVALID_PARAMETERS = 87;
            const LONG ERROR_NO_MORE_ITEMS = 259;


            const LONG KEY_ALL_ACCESS = 0x3f;

            const LONG REG_OPTION_NON_VOLATILE = 0;
}

Note that the dll should now be added to the references of your project and that the dll should be available in the seachpath of your application.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1487570
Any questions left???
0
 
LVL 1

Author Comment

by:hasmet
ID: 1487571
dllname is for using exported dll functions, not ?
how am I going to use it for VBA to understand structures
or enums in my IDL ?? few more lines of explanation please,
and send it as an answer not a comment and let us conclude
this part, for now so you get your points. thanks
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 400 total points
ID: 1487572
Just put the types inside the module part. The module part was basically the answer to your question on how to create a module.

VBA does not now user types.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question