Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Enumerated constants

Status
Not open for further replies.

pankajv

Programmer
Jan 30, 2002
178
0
0
IN
I have a class which have lot of enum defined in it. This class along with other classes(have some functionality) have been packaged in a project and I have created a dll for the project. There is another project where I need to call different methods and need to access the different enumerated constants. For some reason we need to use late binding. If I try to access a enumerated constant I am getting a blank value. On the other hand if I do an early binding things work perfectly fine. Is there a way by which I can access the enumerated constant while using late binding.

For e.g. If I directly try to use the constant adOpenDyanamic defined under CursonTypeEnum, without referencing to ADO, I get a blank value, whereas if I refer to ADO, I get a value of 2.
 
Late binding implies you don't have access to the IDL of a object. Seeing the ENUMs are part of that IDL but you don't want to use early binding you are out of luck really.

Late binding actually works this way.

You create a OBJECT. OBJECT has knows about the IDispatch interface.

When you do something like

Code:
Dim tObj As Object

Set tObj = CreateObject("MyLib.MyClass")

tObj.DoSomething ...

VB actually translates this to something like this

Code:
Dim tObj As Object

Set tObj = CreateObject("MyLib.MyClass")

id = tObj.GetIDsOfNames "DoSomething"
tObj.Invoke id

tObj never knows about your actual objects IDL. The only way to do this is to reference your library.

I suspect that you may be using late binding to avoid the problem with binary compatibility where your company is constantly changing the IDL of the library and don't want to modify exsisting programs. If this is true this is the bad/lazy way of handling this problem.

one thing you might want to concider is to bring all those enums into your program. But if they change you'll have to change them in 2 places. No way around it....you can't have your cake and eat it too.
 
Thanks for your response. Actually we have developed a common component for the client, which has been used in several projects. We have been using early binding. but in one of our last projects where the application has to share the server with another server had an older version. Due to this we had lot of problems while moving the application to production. That is the reason why we wanted to use the late binding.
 
A note. You can not have 2 versions of the same library installed on the same machine.

If you use Early binging the classid of class is embedded into the program. The system uses this classid to look up what library contains that class in the registry.

In late binding it uses the ProgID to find the library via the registry. If you have 2 DLLs on the machine at one time only 1 of them will be used via late binding. It is possible to have early binding use 2 different DLLs but this is a hack and a bad situation to get in.

I bring this up because I've had customers that I have taught that ran Dev, Testing and QA on the same box at the same time thinking they where using different DLLs because they where in different directories. Unlike normal Windows DLL the ActiveX DLL don't have to be in the current path or system path. Their location doesn't matter if they are registered. If they are not registered then you can't use them. Thus if you have 1 DLL in your application path but another one that has been registered after in some obsure path then the 2nd one will be the one that is used by the program not the DLL that is sitting next to the application.
 
Now I'd like to do a palette color dialog(the same color box in Office 2000) or reuse this component in Office. Please tell me if you know how to do this. Thanks very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top