Board index » Visual Studio » Using Open, Close , Lock, Unlock, etc. as dll method names

Using Open, Close , Lock, Unlock, etc. as dll method names

Visual Studio247
Is there any way to create a VB DLL and use a reserved word as a method name. The situation I have is that I have a very large

application that is built around a 3rd party com library. The library is now obsolete and no longer supported. I want to migrate

the application to something else. My initial plan was to build a replacement dll that mimics the existing object model. That way

I can develop and test the dll and then just drop it in place of the original and not have to mess with the code. This will be

fairly simple to implement. The problem is that the original component uses method names that are reserved (Open, Close, Lock,

Unlock, etc.) Is there some way around this? At this point I have the Methods called Open_, Close_, etc. Is there some way to

alias them to the correct names using a type library? If so, how? If not, is there any other way.



TIA



--

Al Reid


-
 

Re:Using Open, Close , Lock, Unlock, etc. as dll method names



"Al Reid" <areidjr@reidDASHhome.com>wrote in message

Quote
Is there any way to create a VB DLL and use a reserved word as a method

name. The situation I have is that I have a very large

application that is built around a 3rd party com library. The library is

now obsolete and no longer supported. I want to migrate

the application to something else. My initial plan was to build a

replacement dll that mimics the existing object model. That way

I can develop and test the dll and then just drop it in place of the

original and not have to mess with the code. This will be

fairly simple to implement. The problem is that the original component

uses method names that are reserved (Open, Close, Lock,

Unlock, etc.) Is there some way around this? At this point I have the

Methods called Open_, Close_, etc. Is there some way to

alias them to the correct names using a type library? If so, how? If

not, is there any other way.



TIA





You need to be a bit more specific as this shouldn't be a problem. All

methods exposed in an ActiveX component (the "3rd party com library" ?) have

to be fully qualified - so there would be no 'conflict'. (eg. look at how

many VB objects/controls/&etc expose Open and Close methods.)



If the component is a straight Dll and not an ActiveX component, then yes,

you could use a typelib, or just redefine the sub/function name in a Declare

directive.



So I must be missing something. <g>



-ralph





-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names

"Ralph" <nt_consulting64@yahoo.com>wrote in message news:GdKdnbVBrLNrj4DYnZ2dnUVZ_t2dnZ2d@arkansas.net...

Quote




You need to be a bit more specific as this shouldn't be a problem. All

methods exposed in an ActiveX component (the "3rd party com library" ?) have

to be fully qualified - so there would be no 'conflict'. (eg. look at how

many VB objects/controls/&etc expose Open and Close methods.)



If the component is a straight Dll and not an ActiveX component, then yes,

you could use a typelib, or just redefine the sub/function name in a Declare

directive.



So I must be missing something. <g>



-ralph







Ralph,



If I place the Procedure definition below into my class module I get a syntax error (red line)





Public Function Open(ByVal Lock As Boolean) As Boolean

'Code to open the object

End Function



Therefore, I can't use "Open" as a procedure name or "Lock" as a parameter. If I change "Open" to "Open_" and "Lock" to "Lock_"

then I can compile the vb ActiveX DLL project. I really don't care about the parameter name as it really can be anything meaningful

and will not require a change to my application.



Perhaps I'm missing something as well (I hope so).



--

Al Reid





-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names



"Al Reid" <areidjr@reidDASHhome.com>wrote in message

Quote
"Ralph" <nt_consulting64@yahoo.com>wrote in message

>

>

>You need to be a bit more specific as this shouldn't be a problem. All

>methods exposed in an ActiveX component (the "3rd party com library" ?)

have

>to be fully qualified - so there would be no 'conflict'. (eg. look at

how

>many VB objects/controls/&etc expose Open and Close methods.)

>

>If the component is a straight Dll and not an ActiveX component, then

yes,

>you could use a typelib, or just redefine the sub/function name in a

Declare

>directive.

>

>So I must be missing something. <g>

>

>-ralph

>

>



Ralph,



If I place the Procedure definition below into my class module I get a

syntax error (red line)





Public Function Open(ByVal Lock As Boolean) As Boolean

'Code to open the object

End Function



Therefore, I can't use "Open" as a procedure name or "Lock" as a

parameter. If I change "Open" to "Open_" and "Lock" to "Lock_"

then I can compile the vb ActiveX DLL project. I really don't care about

the parameter name as it really can be anything meaningful

and will not require a change to my application.



Perhaps I'm missing something as well (I hope so).



--

Al Reid





Nope - it ain't you - it's me!



You are absolutely correct - you can't use those names to create a method in

VB. I am completely and quite embarrassing wrong.



[Should have tested it before I opened my big mouth.]



My only defense is that I usually use ATL (where these are not key words).

When I do use VB I almost always expose full services and not just

instructions. But that is pretty weak. <g>



My apologizes.

-ralph













-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names

"Ralph" <nt_consulting64@yahoo.com>wrote in message news:_qKdnbpQpN-Rg4DYnZ2dnUVZ_tOdnZ2d@arkansas.net...

Quote




Nope - it ain't you - it's me!



You are absolutely correct - you can't use those names to create a method in

VB. I am completely and quite embarrassing wrong.



[Should have tested it before I opened my big mouth.]



My only defense is that I usually use ATL (where these are not key words).

When I do use VB I almost always expose full services and not just

instructions. But that is pretty weak. <g>



My apologizes.

-ralph





No problem Ralph. I thought that it could be done by placing brackets around the name (i.e. [Open]) in some previous version of VB,

perhaps vb4.



There has to be some trick. I really don't want to have to do this in another language like c++, c# or vb.net. My proficiency

level in c++ is at best average and I don't have enough time in the budget to be inefficient. I don't want to use .Net because I

don't want to add the .Net Framework dependency. The app is too large to migrate (re-write) to .Net...



What to do? There must be some IDL or other way to make this work. Any other suggestions? Karl, Bob, Ken, Rick, Jeff, Larry?

Anyone????



--

Al Reid





-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names

"Al Reid" <areidjr@reidDASHhome.com>wrote in message

Quote
Is there any way to create a VB DLL and use a reserved word as a method

name. The situation I have is that I have a very large

application that is built around a 3rd party com library. The library is

now obsolete and no longer supported. I want to migrate

the application to something else. My initial plan was to build a

replacement dll that mimics the existing object model. That way

I can develop and test the dll and then just drop it in place of the

original and not have to mess with the code. This will be

fairly simple to implement. The problem is that the original component

uses method names that are reserved (Open, Close, Lock,

Unlock, etc.) Is there some way around this? At this point I have the

Methods called Open_, Close_, etc. Is there some way to

alias them to the correct names using a type library? If so, how? If

not, is there any other way.



TIA



--

Al Reid





Start a new ActiveX DLL project, add the 3rd party DLL as a reference, then

use Implements keyword for each object in separate class files. You may have

to create a type library if you have problems. I tried this with a library

that has a class with Open method and it worked. The one I used is

OLELIB.TLB, which can be downloaded from here:



www.mvps.org/emorcillo/en/code/vb6/index.shtml">www.mvps.org/emorcillo/en/code/vb6/index.shtml



My test implements line:



Implements olelib.ITextDocument



When you compile, VB6 will show errors that you must implement each method,

just click on each event and leave it with no code inside the event

declaration to avoid the error, however, you could put some code if you want

to.



Finally, make sure that you familiarize yourself with Object Browser(F2),

you will find it of great help.









-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names



"Al Reid" <areidjr@reidDASHhome.com>wrote in message

Quote
"Ralph" <nt_consulting64@yahoo.com>wrote in message

news:_qKdnbpQpN-Rg4DYnZ2dnUVZ_tOdnZ2d@arkansas.net...

>

>

>Nope - it ain't you - it's me!

>

>You are absolutely correct - you can't use those names to create a method

>in

>VB. I am completely and quite embarrassing wrong.

>

>[Should have tested it before I opened my big mouth.]

>

>My only defense is that I usually use ATL (where these are not key

>words).

>When I do use VB I almost always expose full services and not just

>instructions. But that is pretty weak. <g>

>

>My apologizes.

>-ralph

>



No problem Ralph. I thought that it could be done by placing brackets

around the name (i.e. [Open]) in some previous version of VB,

perhaps vb4.



You might be thinking of Enum type definitions. You can enclose identifiers

in brackets within an Enum. For example:



Public Enum Test

[_a] = 1

b = 2

End Enum



What this does is cause 'a' to be hidden from IntelliSense. It's actually

the underscore that hides it. The brackets allow for the identifier to

begin with the underscore character. The brackets also allow the use of

reserved words in an Enum. For example, this is valid and allowed:



Public Enum Test

[Open] = 1

[Close] = 2

[Lock] = 3

[Unlock] = 4

End Enum



I don't see how this is going to help you though.





Quote
There has to be some trick. I really don't want to have to do this in

another language like c++, c# or vb.net. My proficiency

level in c++ is at best average and I don't have enough time in the budget

to be inefficient. I don't want to use .Net because I

don't want to add the .Net Framework dependency. The app is too large to

migrate (re-write) to .Net...





I doubt very much there's anything you can do. Those are reserved words in

VB and its simply not going to allow you to use them as identifiers

(procedure names, variable names, etc.) except in an Enum definition as

described above.





--

Mike

Microsoft MVP Visual Basic





-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names



"Al Reid" <areidjr@reidDASHhome.com>wrote in message

Quote
Is there any way to create a VB DLL and use a reserved word as a method

name. The situation I have is that I have a very large

application that is built around a 3rd party com library. The library is

now obsolete and no longer supported. I want to migrate

the application to something else. My initial plan was to build a

replacement dll that mimics the existing object model. That way

I can develop and test the dll and then just drop it in place of the

original and not have to mess with the code. This will be

fairly simple to implement. The problem is that the original component

uses method names that are reserved (Open, Close, Lock,

Unlock, etc.) Is there some way around this? At this point I have the

Methods called Open_, Close_, etc. Is there some way to

alias them to the correct names using a type library? If so, how? If

not, is there any other way.



TIA



--

Al Reid







I remember I had the same question a while ago and couldn't find any advise.

I thought about one solution then, but never implemented it in practice due

to unreasonable complexity and limited applicability. Anyway, these are my

untested thoughts.



First of all it should work only if your classes (those with reserved

keywords) are PublicNotCreatable and your library exposes them to client via

hierarchical object model.

You can create an IDL file with the full interface of your class. Reference

final TLB in your project and use that interface with Implements keyword.

Now you expose that Interface to the client - not a class itself. Client

doesn't see such substitution and doesn't actually care about it.



Let say you have a top class in your module, which is, let say, Application

and another class, let say, Connection, which should have a method Close.

Internally, you have a class, which you name as CoConnection, and in TLB it

is called Connection.



Now, conceptually, it looks like this:



'In Application

Public Property Get Connection() As Connection

dim obj as CoConnection

set obj=new CoConnection

set Connection=obj 'here you, in fact, pass an interface Connection of

class CoConnection, but client does see Connection only

set obj=nothing

End Property





'In CoConnection

Implements Connection



Private Sub Connection_Close()

'here either call internal class's method (e.g. your Close_) or put full

functionality. The latter is, perhapse, better (in this case class can be

used directly without interface)

End Sub



I don't remember, if there are other details, but in general, it is as

explained above.



Complexity, as I said before, is that you have to create interface in IDL

for ALL of your methods and properties, not only for those with reserved

keywords. Otherwise, you client should be aware about two interfaces, which

compromises your goal. And if those classes are directly creatable by

client, then it doesn't work either - client must do the same additional

step (declare a variable of your interface type, create concrete class and

then assign it to that variable) as shown in Application class.



I am sure this can be combined with advanced techniques of replacing VTable,

but I never went so far - in my case I decided that all these doesn't worth

the result. You might arrive to the same conclusion - time you spend on all

these tricks may greatly exceed time required for context replacement of few

[dozens or even hundreds] method calls in your client.



I don't know whether I overlooked any simpler method of doing it.



Dmitriy.







-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names



Quote
>Al Reid





Start a new ActiveX DLL project, add the 3rd party DLL as a reference, then

use Implements keyword for each object in separate class files. You may have

to create a type library if you have problems. I tried this with a library

that has a class with Open method and it worked. The one I used is

OLELIB.TLB, which can be downloaded from here:



www.mvps.org/emorcillo/en/code/vb6/index.shtml">www.mvps.org/emorcillo/en/code/vb6/index.shtml



My test implements line:



Implements olelib.ITextDocument



When you compile, VB6 will show errors that you must implement each method,

just click on each event and leave it with no code inside the event

declaration to avoid the error, however, you could put some code if you want

to.



Finally, make sure that you familiarize yourself with Object Browser(F2),

you will find it of great help.









I tried that but I still get the error in the procedure declaration of the Open function. In a class module I have:



Option Explicit



Implements RepServerLib.RepServer



Public Function Open() As Boolean



End Function



Perhaps I didn't understand what you were telling me to do.



BTW, I've been using VB since version 2 and I'm quite familiar with the Object browser and the help system.



Thanks,



--

Al Reid







-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names

"Al Reid" <areidjr@reidDASHhome.com>wrote in message

Quote


>>Al Reid

>

>

>Start a new ActiveX DLL project, add the 3rd party DLL as a reference,

>then

>use Implements keyword for each object in separate class files. You may

>have

>to create a type library if you have problems. I tried this with a

>library

>that has a class with Open method and it worked. The one I used is

>OLELIB.TLB, which can be downloaded from here:

>

>www.mvps.org/emorcillo/en/code/vb6/index.shtml">www.mvps.org/emorcillo/en/code/vb6/index.shtml

>

>My test implements line:

>

>Implements olelib.ITextDocument

>

>When you compile, VB6 will show errors that you must implement each

>method,

>just click on each event and leave it with no code inside the event

>declaration to avoid the error, however, you could put some code if you

>want

>to.

>

>Finally, make sure that you familiarize yourself with Object Browser(F2),

>you will find it of great help.

>

>

>



I tried that but I still get the error in the procedure declaration of the

Open function. In a class module I have:



Option Explicit



Implements RepServerLib.RepServer



Public Function Open() As Boolean



End Function



Perhaps I didn't understand what you were telling me to do.



Please download "OLELIB.TLB - OLE interfaces & functions v1.7" from the link

that I provided, then start a new ActiveX DLL project, in the project's

references, browse to "olelib.tlb" file(You won't see it on the list of

references at first) and select it, this registers the TLB file.



Now, in Class1, add the following line:



Implements olelib.ITextDocument



Now on the code window, select "ITextDocument" from the left combo, then

choose "Open" in the right combo. This will show the following:



Private Sub ITextDocument_Open(pVar As Variant, ByVal flags As

olelib.tomOpenFlags, Optional ByVal CodePage As Long = 0&)



End Sub



You can add a simple message box there if you want.



If you try to compile or run, you get an error message, to avoid that, you

have to click on every item in the right combo, which creates the

declaration for each method and property. No need to put code inside each

method or property at this stage. After that, you can recompile or run the

project.



In the 3rd party DLL, if you don't see "RepServer" in the left combo, then

you have to make a type library for that DLL.







-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names

"Al Reid" <areidjr@reidDASHhome.com>wrote in message

<cut>

Quote
There has to be some trick. I really don't want to have to do this

in another language like c++, c# or vb.net.



Would it be feasible to do an object in C++ that just acts as bridge and

delegates to your VB class? The client would instantiate the C++ object

which would immediately instanitate the VB object and the "Close" method of

the C++ object would call the "[Close_]" method of the VB object passing all

parameters/return values, etc? It'd be another layer of overhead and

another DLL but might be the quickest and most maintainable solution since

it'd be minimal C++ work.



--

Reply to the group so all can participate

VB.Net: "Fool me once..."



-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names

"Bob Butler" <tiredofit@nospam.ever>wrote in message news:OHsyvd%234GHA.4616@TK2MSFTNGP05.phx.gbl...

Quote
"Al Reid" <areidjr@reidDASHhome.com>wrote in message

news:%23whVl%2384GHA.3732@TK2MSFTNGP05.phx.gbl

<cut>

>There has to be some trick. I really don't want to have to do this

>in another language like c++, c# or vb.net.



Would it be feasible to do an object in C++ that just acts as bridge and

delegates to your VB class? The client would instantiate the C++ object

which would immediately instanitate the VB object and the "Close" method of

the C++ object would call the "[Close_]" method of the VB object passing all

parameters/return values, etc? It'd be another layer of overhead and

another DLL but might be the quickest and most maintainable solution since

it'd be minimal C++ work.



--

Reply to the group so all can participate

VB.Net: "Fool me once..."





Bob,



That may be the way to go. I hadn't thought of that. I think I will continue with the current naming (Open_, Close_, etc) and

once I'm done I will have a couple of options. One is your suggestion and the second is to simply search and replace using the

slightly modified naming.



Thanks,



--

Al Reid





-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names



"Bob Butler" <tiredofit@nospam.ever>wrote in message

Quote
"Al Reid" <areidjr@reidDASHhome.com>wrote in message

news:%23whVl%2384GHA.3732@TK2MSFTNGP05.phx.gbl

<cut>

>There has to be some trick. I really don't want to have to do this

>in another language like c++, c# or vb.net.



Would it be feasible to do an object in C++ that just acts as bridge and

delegates to your VB class? The client would instantiate the C++ object

which would immediately instanitate the VB object and the "Close" method

of

the C++ object would call the "[Close_]" method of the VB object passing

all

parameters/return values, etc? It'd be another layer of overhead and

another DLL but might be the quickest and most maintainable solution since

it'd be minimal C++ work.





Something to consider.



Creating such a "bridge" C++ ActiveX would as a byproduct actually be

creating an IDL (for the typelib), which with tweaking would easily become

the Interface definition for expvb's and Dmitriy's solution.



-ralph





-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names

"Al Reid" <areidjr@reidDASHhome.com>wrote in message

Quote
Is there any way to create a VB DLL and use a reserved word as a method

name. The situation I have is that I have a very large

application that is built around a 3rd party com library. The library is

now obsolete and no longer supported. I want to migrate

the application to something else. My initial plan was to build a

replacement dll that mimics the existing object model. That way

I can develop and test the dll and then just drop it in place of the

original and not have to mess with the code. This will be

fairly simple to implement. The problem is that the original component

uses method names that are reserved (Open, Close, Lock,

Unlock, etc.) Is there some way around this? At this point I have the

Methods called Open_, Close_, etc. Is there some way to

alias them to the correct names using a type library? If so, how? If

not, is there any other way.



TIA



--

Al Reid



IMO, the easiest way would be to qualify those names better.... like

OpenFile, CloseFile (or what ever they do). I remember hearing about

problems with underscores too.. can't recall the details... if you really

want to get fancy, I believe you can build the DLL to your specs and modifiy

the internal typelib. Major pain if you ask me.



If you just use "better" names for the methods, you should be able to do a

global "Search and Replace" to fix the code. Since the new DLL can't

possible be binary compatible with the 3rd party version (uness you do more

typelib hacking.. which will surely cause DLL hell), you might as well come

up with new names for the methods.



--

Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..

In Loving Memory - www.vbsight.com/Remembrance.htm">www.vbsight.com/Remembrance.htm





-

Re:Using Open, Close , Lock, Unlock, etc. as dll method names

Hi,



you could fiddle with the dll's typelib.



Declare eg a sub later be called "Open" as Public Sub Open_



In your code use this names, that is, all internal calls are made to Open_.



Then edit the typelib and change the name of Open_ to Open.



For editing the typelib, if you own his book, Matt Curland provides an

in place typelib editor. Of course you have to edit the typelib again

after every compilation of the dll.



Or you could go this path (which I assume it will work): create a

textual (decompiled) version of the typelib using Oleview.exe and save

it to disk. Edit the typelib (change the method name). Recompile it

using midl.exe. Now replace the dlls internal typelib with the changed

and compiled typelib. Tools like Ressourcehacker can do this.



--

Ulrich Korndoerfer



VB tips, helpers, solutions ->www.proSource.de/Downloads/">www.proSource.de/Downloads/



-----------------------------------------------------------------------

Plea for a bright future for VB classic.

Sign the petition to Microsoft: ->classicvb.org/petition/">classicvb.org/petition/

-----------------------------------------------------------------------

-