Results 1 to 11 of 11

Thread: Using VB6 Collections, Variants, & Byte Arrays in C++

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,057

    Using VB6 Collections, Variants, & Byte Arrays in C++

    Last edited by dz32; Jan 21st, 2020 at 07:39 AM.

  2. #2
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Using a VB6 Collection in C++

    This
    Code:
    #define EXPORT comment(linker, "/EXPORT:"__FUNCTION__"="__FUNCDNAME__)
    . . . does not work in VC6 as there is no `__FUNCTION__` (not __FUNCDNAME__) unfortunately. It's such a nice hack provided that stdcall exports get decorated a lot (w/ or w/o extern "C" modifier).

    I've been reading your blog and tested some of the samples in LinkTool. Very excited about staticly linking C/C++ .obj files as it opens a whole new world of possible hacks!

    Unfortunately couldn't use [VBCompiler]/LinkSwitches .vbp hack to *replace* VB6 module .obj files with C/C++ surrogates. Had to make a replacement linker that swaps VB6 compiled .obj files with surrogate .cobj files it founds in target folder. This works very well and currently I'm considering reimplementing some of my unstable VB6 projects with static C/C++ replacement functions.

    cheers,
    </wqw>

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,057

    Re: Using a VB6 Collection in C++

    [...]
    Last edited by dz32; Apr 26th, 2019 at 12:05 PM.

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Using a VB6 Collection in C++

    In VC6 #pragma comment(linker, "/EXPORT:DllCreateInstance=_DllCreateInstance@4") works just fine (no .def file whatsoever). The `_DllCreateInstance@4` part is the nuisance that has to be precise -- @4 is the number of bytes as function params, so this changes when function prototype is modified, not to mention that function name has to be in sync obviously. The EXPORT macro wraps and hides this impl detail nicely.

    Not sure about the generated .lib but you can always generate it from final .dll like explained here. Instead of `dumpbin /exports` you can even use tiny_impdef from TCC project. Honestly I've never understood the .lib nonsense cl.exe uses. Most other linkers have -l<dll_file> option to link to PE exports straight (e.g. gcc and TCC)

    cheers,
    </wqw>

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,057

    Re: Using a VB6 Collection in C++

    [...]
    Last edited by dz32; Apr 26th, 2019 at 12:05 PM.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,057

    Re: Using a VB6 Collection in C++

    [...]
    Last edited by dz32; Apr 26th, 2019 at 12:04 PM.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,057

    Re: Using a VB6 Collection in C++

    [...]
    Last edited by dz32; Apr 26th, 2019 at 12:04 PM.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,057

    Re: Using a VB6 Collection in C++

    [...]
    Last edited by dz32; Apr 26th, 2019 at 12:03 PM.

  9. #9
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Using VB6 Collections, Variants, & Byte Arrays in C++

    The Unicode<->ANSI magic is widely understood (it's working in both directions). The length prefix on temp ANSI strings is new info for me -- totally underused and a bit useless IMHO.

    It also makes no sense to use ((long *)str)[-1] to get string size when your param is LPSTR and strlen is the way to go. If you use BSTR for param type then you expect prefix and *unicode* strings.

    Have no idea what C/C++ type to use for ansi string with length prefix. `SysAllocStringByteLen` is prototyped to return BSTR -- a hack they can get away with as the BSTR length prefix is in *bytes*, not wchars.

    cheers,
    </wqw>

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,057

    Re: Using VB6 Collections, Variants, & Byte Arrays in C++

    [...]
    Last edited by dz32; Apr 26th, 2019 at 12:03 PM.

  11. #11
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,673

    Re: Using VB6 Collections, Variants, & Byte Arrays in C++

    The length prefix on temp ANSI strings is new info for me -- totally underused and a bit useless IMHO.
    When VB6 translates a string to ANSI it translate it to a BSTR but this string contains the ANSI string and the prefix consist number of bytes of ANSI string. Thus if you pass a string from a VB6 program to a DLL it will contain a prefix length anyway independent of ByVal/ByRef statement. It affects only to the format of the string (ANSI/UNICODE).

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