CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Jul 2002
    Location
    Germany
    Posts
    10

    Generic API in VB DLL possible?

    Hi folks,

    i want to be confirm that isn´t possible to make a generic API (interface) in DLLs developed in VB. That means -- the interface can not be (re-)defined after linking ...

    If you see a chance to make it in VB, please, tell me how ...

    By the way, do you have any suggestions to solve those problems in VB?
    Specially patterns are willcome ...

    Thx a lot

    Greetings from Germany
    St. Claus
    Yeah! Your code is so sexy!

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    redefining interfaces...

    If you mean you want a non com interface via Vb, that should not be possible.
    If you mean you want a Com interface, and once you have it you want
    inherit and ovverride, the override is not possible, as far as I know.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jul 2002
    Location
    Germany
    Posts
    10

    I agree - trying facade pattern

    Hi Cimperiali,

    thank you for the answer.

    I agree that overriding is not possible, but i want to be sure.
    Naturally, I prefer VC++ for generic developments with or without COM. But the customer spend 1.2 M € for a VB development, so i ´ve some resistance ...

    Yeah, i ´ve to design an activeX dll, so COM with inheritence is an option.
    But i am not sure the core team can handle this...

    Perhaps an easy way is to set a static interface in a facade pattern (GoF) and re-design the dll if necessary.

    Anyway, thx again.

    cu

    St. Claus
    Last edited by St. Claus; August 17th, 2004 at 04:19 AM.
    Yeah! Your code is so sexy!

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    You could have some C++ components Com compliant...and call them from Vb
    (but I do not hold enough knowledge on C++ to tell if this could solve)
    One thing more:
    In Vb, you can declare Api using aliases, and have "As Any" parameters. Might it
    help for what you're looking for (if you can make C++ components under the hood...) ?
    In any case, Vb (6.0) inheritance is not a true inheritance, so beware....
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Jul 2002
    Location
    Germany
    Posts
    10

    Thx for hints

    Hi Cimperiali,

    thank you for your hints to solve my problem.

    I start to become nuts to set an inheritance in a semi-oo language like VB.
    So i beware now...

    By the way, C++ developed normal DLLs are only compilant to VB if there are using C-Syntax in interfaces not C++-Syntax. That means no imports or otherwise exports of C++ classes, member functions and overload functions are possible. In this case you might use COM.

    I think may be an array attribute "as Any" type is the best way...

    greetings
    St. Claus
    Yeah! Your code is so sexy!

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    Quote Originally Posted by St. Claus
    I think may be an array attribute "as Any" type is the best way...
    Not with Com, however: that could work with Api (or with your C_non_com
    object....)
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  7. #7
    Join Date
    Nov 2002
    Location
    Baby Land
    Posts
    646
    Some other insight, you can also use IDL to define the interface and generate a tlb file, You can implements the TLB interface in VB Class, so this is kinda like in C ATL to use a separate typelib to define the interface.

    I use this technique so I can recompile my DLL even with no binary compatibility but the client program will still run normally cause it reference the Typelib not the DLL directly.

  8. #8
    Join Date
    Jul 2002
    Location
    Germany
    Posts
    10

    Smile Ufff!

    Hi folks!

    @Cimperiali:
    What´s the trouble concerning array in COM?
    Thx.

    @Luthv:
    Wow, hero stuff! - It works?
    ...I can recompile my DLL even with no binary compatibility but the client program will still run normally cause it reference the Typelib not the DLL directly.
    Means - the old release of dll is in vtable, while you are compiling?!?
    Otherwise the app will still crashing after function call. Right?

    To say it clear:
    - VB client implements a tbl file
    - tbl file includes IDL
    - IDL defines typelib
    - DLL deploys typelib

    Where is the dll linking?
    Can you tell me a little more about TBL File, please?

    Thank you for your great Ideas, too!

    regards
    St. Claus
    Last edited by St. Claus; August 18th, 2004 at 03:05 PM.
    Yeah! Your code is so sexy!

  9. #9
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    What´s the trouble concerning array in COM?
    Not a big one if you can manage the copymemory Api, or if you are creating a C
    dll that could be declared as api function inside a Vb porgram.

    Matter is: if you are going to work with vb only, you do not have "as any"
    (but ytou could work with "Variant" and "Object" types - only not everithing will
    be "coerced to a variant" when it comes the time to move through com: "only "
    things "defined in a public creatable class"...Moreover, unless you play under the
    hood (with CopyMemory api and few documented Vb instructions like "VarPtr"and
    "ObjPtr"), you will not be able to pass arrays byVal...

    That is: limitations do exist, but I cannot say they are so big you cannot work
    with arrays...it depend more on the whole thing you are making (with Vb only?
    with C and Vb?) and how much you can go "under the hood" .
    As I am only a Vb develper and do not feel comfortable playing lower-side, I tend
    to avoid generic variants in my objects, and work with classes and collection of
    classes which become objects I can "marshal" more easily....

    As you do not have true inheritrance in Vb, and you cannot overload, you might
    have to choose between a few unspecific objects with lot of code to manage all
    cases or more objects more specialized that can do each less jobs but are more
    focused on their task. I do prefer to have some more object rather than less but
    too much complex...

    You might find this interesting:
    http://www.mvps.org/vb/hardcore/
    'errata corrige is here:
    http://support.microsoft.com/default...NoWebContent=1
    Implementing multiple interfaces
    The CBugFilter class presented earlier implemented the IFilter interface. You could
    access the IFilter interface or the default _CBugFilter interface through separate
    object variables. Think about this for a moment. If you can get two interfaces
    through polymorphism, why not three interfaces? Why not 12? Why not 137
    interfaces?
    [Zipped an extract of that article]
    Attached Files Attached Files
    Last edited by Cimperiali; August 19th, 2004 at 06:02 PM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  10. #10
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Tlb

    Make a simple vb dll project.
    Before making the dll, go to project properties
    Select component tab
    check the "make for remote server execution" check box
    Now make dll in an empty folder -better you then get that dll, rename it,
    set binary compatiblity to it make one more with the original name
    (thus without overwriting the old one that you have renamed)-

    go inside that folder...any Tlb file there?

    Now make a small exe standard project and add a reference to the Tlb file
    Can you declare a variable as TheObject.TheCreatableClass you coded in the
    dll?


    Now follow this link [from a post of Luthv!]
    http://www.vbaccelerator.com/home/VB...ty/article.asp
    and from Msdn:

    Type libraries are compound document files (.tlb files) that include information about types and objects exposed by an ActiveX application. A type library can contain any of the following:

    Information about data types, such as aliases, enumerations, structures, or unions.
    Descriptions of one or more objects, such as a module, interface, IDispatch interface (dispinterface), or component object class (coclass). Each of these descriptions is commonly referred to as a typeinfo.
    References to type descriptions from other type libraries.
    By including the type library with a product, the information about the objects in the library can be made available to the users of the applications and programming tools. Type libraries can be shipped in any of the following forms:

    A resource in a dynamic link library (DLL). This resource should have the type TypeLib and an integer identifier. It must be declared in the resource (.rc) file as follows:
    1 typelib mylib1.tlb
    2 typelib mylib2.tlb

    There can be multiple type library resources in a DLL. Application developers should use the resource compiler to add the .tlb file to their own DLL. A DLL with one or more type library resources typically has the file extension .olb (object library).

    A resource in an .exe file. The file can contain multiple type libraries.
    A stand-alone binary file. The .tlb (type library) file output by the MkTypLib utility is a binary file.
    Last edited by Cimperiali; August 18th, 2004 at 05:59 PM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  11. #11
    Join Date
    Nov 2002
    Location
    Baby Land
    Posts
    646
    I've attach a simple project using tlb and IDL (I compiled the tlb with MIDL.exe from visual Studio). Please register the two tlb's with the utility from vbaccelerator.com. Then run the gTest.vbg.
    Attached Files Attached Files

  12. #12
    Join Date
    Jul 2002
    Location
    Germany
    Posts
    10

    Thumbs up Guru gathering!

    Uiih! - Great help!

    May be i shoud send two boxes of good german beer as fee. But i can´t find Baby Land on map (and of course beers are not the right drink for kids) and Italians prefer wines i guess.

    Ok, gi´me some time to aprove and learn my lessons now.
    I´ve to do my job first ...

    Thank you very much.

    ciao
    St. Claus
    Yeah! Your code is so sexy!

  13. #13
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Smile

    Quote Originally Posted by St. Claus
    May be i shoud send two boxes of good german beer as fee. But i can´t find Baby Land[...]and Italians prefer wines i guess
    [...]
    ciao
    Ciao!
    But you can send a beer to Luthv, he is really a precocious baby...
    And I drink really few, but appreciate both wine and beer...You could
    send it by fax or e-mail... ...but you already added to
    reputation, so we have been already rewarded...

    Have a nice day,
    Cesare
    Last edited by Cimperiali; August 19th, 2004 at 06:06 PM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured