dcsimg
Results 1 to 12 of 12

Thread: How do I define constants in ActiveX DLL?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    971

    How do I define constants in ActiveX DLL?

    I want to define a constant in an ActiveX DLL, so when the AXDLL is added to the project in Project>References, it will make the constant be added to the project, just as if the constant had been defined as Public in a module in the actual program you are using the constant in. Is this possible?

  2. #2
    Fanatic Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    873

    Re: How do I define constants in ActiveX DLL?

    Constant in a typelib, compiled from IDL -- yes.

    Real constant in AxDLL, compiled from VB -- no.

    You can impl a workaround with a global class and a same named property, but this wil incur unnecessary run-time performance penalty.

    cheers,
    </wqw>

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    971

    Re: How do I define constants in ActiveX DLL?

    Quote Originally Posted by wqweto View Post
    Constant in a typelib, compiled from IDL -- yes.

    Real constant in AxDLL, compiled from VB -- no.

    You can impl a workaround with a global class and a same named property, but this wil incur unnecessary run-time performance penalty.

    cheers,
    </wqw>
    But what if I want my DLL to use the constant, while also allowing my program (which will use the DLL) to access the same constant?

  4. #4

  5. #5
    Fanatic Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    873

    Re: How do I define constants in ActiveX DLL?

    Quote Originally Posted by The trick View Post
    Enum?
    Ooops. . . I thought OP was asking for a string constant! :-))

    cheers,
    </wqw>

  6. #6
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,134

    Re: How do I define constants in ActiveX DLL?

    Is it possible to post process it into the resulting typelib already in the DLL?
    At a minimum you could add a second typelib to the same DLL.

    basically the steps could be
    1) extract the IDL code from the DLL using OleView.
    2) modify the IDL to add your enums/constants.
    3) recompile the typelib
    4) replace the typelib resource in the DLL.

    edit: a more complex process outlined here. https://limbioliong.wordpress.com/20...n-atl-com-dll/
    Last edited by DEXWERX; Nov 8th, 2018 at 11:18 AM.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Posts
    971

    Re: How do I define constants in ActiveX DLL?

    Quote Originally Posted by The trick View Post
    Enum?
    Enums are used to define a list of related constants. I want to define one that stands by itself (the number Pi in my case).

  8. #8
    Addicted Member
    Join Date
    Aug 2017
    Posts
    133

    Re: How do I define constants in ActiveX DLL?

    Same question from you 3 years ago: How do I put global constants in my ActiveX DLL?

  9. #9
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,134

    Re: How do I define constants in ActiveX DLL?

    ah well... dil pointed out that MIDL doesn't support floating point constants...
    looks like the OP is out of luck. We can put this to rest for another few years.

  10. #10
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,244

    Re: How do I define constants in ActiveX DLL?

    If it's so important why put the PI constant in an ActiveX dll?
    Or use a global variable or const in the main program.

    Code:
    Public PI As Double
    
    Public Sub Main()
      PI = Atn(1) * 4
    End Sub

  11. #11
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,816

    Re: How do I define constants in ActiveX DLL?

    Here's what I don't understand. Let me outline a somewhat strange scenario where you might want to do this. Let's say you have an ActiveX DLL that has something like "a date or number that represents the last time you visited the client site". And you always recompile and install this ActiveX DLL when you're at a client's site. (Why you wouldn't just recompile the main program, IDK, but let's just suppose.)

    Therefore, you've got some value in the ActiveX DLL that the main program needs. When the main program starts up, why not load this ActiveX DLL, instantiate some class in it, and then have a property (or function) of that class that returns your value, and then store this value in your main program so long as it's running? It would seem that that solves the problem.

    Good Luck,
    Elroy

    EDIT1: Or, just keep the ActiveX DLL's class instantiated, and go to its class properties anytime you needed that value (or those values).
    Last edited by Elroy; Nov 9th, 2018 at 09:34 AM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  12. #12
    PowerPoster
    Join Date
    Jun 2013
    Posts
    3,896

    Re: How do I define constants in ActiveX DLL?

    Quote Originally Posted by Elroy View Post
    When the main program starts up, why not load this ActiveX DLL, instantiate some class in it, and then have a property (or function) of that class that returns your value,...
    Well, that was suggested already in #2 (being the easiest to implement solution).
    As for "Dll-Project-internal usage of a same named constant" - I see not a problem at all:

    within a Class cMyGlobal:
    Code:
    Property Get PI() As Double
      PI = modGlobals.PI
    End Property
    The Dll-ProjectCode will automatically make use of the Public Constant for PI, as defined in modGlobals.bas -
    and any outside Users would use the PI-method of the cMyGlobal.cls (with the already mentioned small performance-penalty).

    Olaf

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width