|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Creating a DLL and calling it from an appI want to store my most common code into a DLL. Creating DLLs is easy enough, but I have a problem. I dont want it to be viewable in the Object Browser. That is, once my whole application is installed on a user's computer... the DLL will get registered and the user will be able to browse through all the functions available in the DLL through VB. I dont want that to happen. Plus, I cant seem to create DLLs similar to the ones provided in Windows. ie. I cant seem to create the 'Declare Function ...' call for them. I tried creating an ActiveX DLL. Added a class module to it. And added a function called ShowMsgBox to it. Now in my normal project, I created a declaration: Private Declare Function ShowMsgBox Lib "dll_project" () As Long When I called this function like this it gives an 'entry point' error: Private Sub Command1_Click() ShowMsgForm End Sub My aim is: * I dont want the DLL to be viewable in the object browser; so the end-user cant mess around with my private functions. * I want to access my DLL in a way similar to accessing APIs. ie. using the Declare Function.. statements * I think this can be achieved without registering the DLL even. * Finally, I think all this can be achieved without creating a license key and setting up a security system. Can it? Please thoroughly guide me through the creation process. Thank you very much! Faraz Azhar
Show quote
Hide quote
"Faraz Azhar" <itz_farazSPAM@hotSPAMmail.com> wrote in message "Plain vanilla" VB will create only ActiveX components. While you can mark news:O5eNwxhZFHA.3712@TK2MSFTNGP09.phx.gbl... > Hello > > I want to store my most common code into a DLL. Creating DLLs is easy > enough, but I have a problem. I dont want it to be viewable in the Object > Browser. That is, once my whole application is installed on a user's > computer... the DLL will get registered and the user will be able to > browse > through all the functions available in the DLL through VB. I dont want > that > to happen. > > Plus, I cant seem to create DLLs similar to the ones provided in Windows. > ie. I cant seem to create the 'Declare Function ...' call for them. > > I tried creating an ActiveX DLL. Added a class module to it. And added a > function called ShowMsgBox to it. Now in my normal project, I created a > declaration: > > Private Declare Function ShowMsgBox Lib "dll_project" () As Long > > When I called this function like this it gives an 'entry point' error: > > Private Sub Command1_Click() > ShowMsgForm > End Sub > > > My aim is: > * I dont want the DLL to be viewable in the object browser; so the > end-user > cant mess around with my private functions. > * I want to access my DLL in a way similar to accessing APIs. ie. using > the > Declare Function.. statements > * I think this can be achieved without registering the DLL even. > * Finally, I think all this can be achieved without creating a license key > and setting up a security system. Can it? > > Please thoroughly guide me through the creation process. Thank you very > much! > > Faraz Azhar your methods as "Hidden" so they don't normally show in the object browser, nothing stops the end developer from selecting the "Show Hidden Members" box in the object browser. Using the add-in below, you can create dlls that require Declares, etc and that contain functionality that won't show in the object browser. fwiw, I've never tried doing this kind of thing. I like intellisense way too much to get rid of it <g> vbAdvance http://www.vbadvance.com/ -- Ken Halter - MS-MVP-VB - http://www.vbsight.com DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Sign up now to help keep VB support alive - http://classicvb.org/petition Please keep all discussions in the groups.. > I want to store my most common code into a DLL. Creating DLLs is easy Why? You can even do this to a degree with standard DLL files (by using the dependency walker among other things), so> enough, but I have a problem. I dont want it to be viewable in the Object > Browser. That is, once my whole application is installed on a user's > computer... the DLL will get registered and the user will be able to browse > through all the functions available in the DLL through VB. I dont want that > to happen. I'm not sure why you're trying to hide it.. > Plus, I cant seem to create DLLs similar to the ones provided in Windows. These are often known a "Standard DLL"'s and VB cannot create them (at least on its own, I believe there are add-ins> ie. I cant seem to create the 'Declare Function ...' call for them. that allow for this though.) If you simply don't want the user to be able to access the functionality of the DLL then set the "Instancing" of the class to 1-Private which means that it can only be used within the DLL. > I tried creating an ActiveX DLL. Added a class module to it. And added a Yes, because you're using an ActiveX DLL rather than a standard DLL - Remember that your function is actually inside a> function called ShowMsgBox to it. Now in my normal project, I created a > declaration: > > Private Declare Function ShowMsgBox Lib "dll_project" () As Long > > When I called this function like this it gives an 'entry point' error: class so you must first start with creating an instance of that class then you can call the method(s) within it. You can also set the instancing to 6-GlobalMultiUse which allows you to call the functions directly without having to create an instance of the class first, this does add additional overhead to your application though (every call you make to it has to check to see if a class already exists and if not, create it) so use sparingly.. > My aim is: The combination of a Private class and/or hidden procedures (tools -> Procedure attributes -> Advanced -> Attributes ->> * I dont want the DLL to be viewable in the object browser; so the end-user > cant mess around with my private functions. Hide this member) may be enough for you here, you can't fully hide them from the object browser with ActiveX DLL's though AFAIK. > * I want to access my DLL in a way similar to accessing APIs. ie. using the Then you'll need to look into standard DLL's> Declare Function.. statements > * I think this can be achieved without registering the DLL even. Correct, only ActiveX DLL's need to be registered with the system.> * Finally, I think all this can be achieved without creating a license key Yup> and setting up a security system. Can it? > Please thoroughly guide me through the creation process. Thank you very Hope this helps,> much! Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ hi Mike,
Here's a wild idea. Compile your ActX DLL into a resource file, using the resource compiler, then add it to your app. At execution time, before you access the dll, load the dll into memory from it's place among the resources (LoadResData), then copy it to a temporary file, and register it. Then use it directly from your app. When you are finished, un-register the dll, and delete it. Then, any pesky snoopers will have difficulty looking at your valuable code (unless they just happen to be around to look when you are running). cheers, jw ____________________________________________________________ You got questions? WE GOT ANSWERS!!! ..(but, no guarantee the answers will be applicable to the questions)
Show quote
Hide quote
> Compile your ActX DLL into a resource file, using the resource It's feasible, however since the DLL is registered with the system during runtime then any other application can 'snoop'> compiler, then add it to your app. > > At execution time, before you access the dll, load the dll into > memory from it's place among the resources (LoadResData), then > copy it to a temporary file, and register it. > > Then use it directly from your app. > > When you are finished, un-register the dll, and delete it. > > Then, any pesky snoopers will have difficulty looking at your > valuable code (unless they just happen to be around to look > when you are running). (or even copy) the DLL whilst it's registered which somewhat defeats the point :) Cheers, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ > It's feasible, however since the DLL is registered with the system during runtime then any other application can 'snoop'> (or even copy) the DLL whilst it's registered which somewhat defeats the and what if by any reason program or windows crash, or theres a powerpoint :) > Cheers, > > Mike > failure or anything.. the dll would keep registered until next time the program is ran and exited cleanly. > the dependency walker among other things), so> Why? You can even do this to a degree with standard DLL files (by using > I'm not sure why you're trying to hide it.. thats different.. i can accept that degree level.> least on its own, I believe there are add-ins> > Plus, I cant seem to create DLLs similar to the ones provided in Windows. > > ie. I cant seem to create the 'Declare Function ...' call for them. > > These are often known a "Standard DLL"'s and VB cannot create them (at > that allow for this though.) If you simply don't want the user to be able to access the functionality of the DLL then> set the "Instancing" of the class to 1-Private which means that it can only be used within the DLL.> uh.. question : VB cannot create standard DLLs.. but an add-in for VB (eg.vbAdvance) can make VB create standard DLL ? how? why ? (just curious) Cant this thing without purchasing add-ins, etc? Can VC++ be of any help in this? Faraz Azhar > uh.. question : VB cannot create standard DLLs.. but an add-in for VB (eg. Correct.> vbAdvance) can make VB create standard DLL ? > how? why ? (just curious) If everyone knew that vbAdvance would be out of a job ;)I would imagine it probably plugs into the linker or something low level like that and simply spits out the correct DLL signatures, there's no reason that VB shouldn't be able to create standard DLL's (there's nothing particularly special about them) it was just never added as a feature. Be aware though that even though it will spit out standard DLL files, they are not quite as portable as those created in other languages as they still require the VB runtime (and indeed will require the engine starting before calls are made to the DLL.) > Cant this thing without purchasing add-ins, etc? Can VC++ be of any help in Yes, you could write the DLL in VC++ or Delphi, indeed there's an article on my site about how to author a DLL in VC++> this? and use it in VB. Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ > Yes, you could write the DLL in VC++ or Delphi, indeed there's an article on my site about how to author a DLL in VC++> and use it in VB. Ok thanks for all that info. Im still a bit shakey at using VC++, not muchaware of the coding techniques in there. Could you also tell if there is any newsgroup for VC++ 6 just like this newsgroup so I could ask beginner level questions in it? Thanks Faraz Azhar > Ok thanks for all that info. Im still a bit shakey at using VC++, not much I would imagine the microsoft.public.vc.* groups would be where to go for that, I don't know offhand which you would> aware of the coding techniques in there. Could you also tell if there is any > newsgroup for VC++ 6 just like this newsgroup so I could ask beginner level > questions in it? want to post to though. Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ Faraz,
> Cant this thing without purchasing add-ins, etc? Can VC++ be of any help Absolutely. C/C++ works just fine.in > this? I'd be happy to write a C DLL for you but I'm afraid that wouldn't be free either. :-( -- Jonathan Wood SoftCircuits http://www.softcircuits.com Available for consulting: http://www.softcircuits.com/jwood/resume.htm OK Ive downloaded vbAdvance.. have experimented it. I can create standard
DLLs and call the functions using Declare statements. New problem: I am trying to place a form inside the DLL. So if I call the function from my app to the DLL, it would display a form (nothing much in that form, a simple plain window). It crashes my app when I try to call the function which is supposed to display the form. Why? Any alternate for it? my code ====== I create an activex dll, add a module to it. add a sub to it and call it ShowMyForm. In that sub the code is: Sub ShowMyForm() Form1.Show vbModal End Sub I put a check at this sub in the Exports list of vbAdvance. It creates the DLL all ok. I declare the sub in my app: Private Declare Sub ShowForm Lib "MyDLL.dll" () And then call the ShowForm sub in a command button event. It crashes my app. If I dont display a form in the DLL, instead I display a messagebox, it works ok. Faraz Azhar "Faraz Azhar" <itz_farazSPAM@hotSPAMmail.com> wrote in message You might have better luck with the ShowWindow API. This API is required if news:usCyeItZFHA.3780@tk2msftngp13.phx.gbl... > > And then call the ShowForm sub in a command button event. It crashes my > app. > If I dont display a form in the DLL, instead I display a messagebox, it > works ok. > you want to show modeless forms from C++ or Delphi so it may help here (note that I mentioned Modeless). '=========== Option Explicit Public Enum ShowWinStates SW_HIDE = 0 SW_SHOWNORMAL = 1 SW_NORMAL = 1 SW_SHOWMINIMIZED = 2 SW_SHOWMAXIMIZED = 3 SW_MAXIMIZE = 3 SW_SHOWNOACTIVATE = 4 SW_SHOW = 5 SW_MINIMIZE = 6 SW_SHOWMINNOACTIVE = 7 SW_SHOWNA = 8 SW_RESTORE = 9 SW_SHOWDEFAULT = 10 SW_FORCEMINIMIZE = 11 SW_MAX = 11 End Enum Private Declare Function ShowWindow Lib "user32" _ (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long Public Sub ShowForm(State As ShowWinStates) Call ShowWindow(Me.hWnd, State) End Sub '=========== -- Ken Halter - MS-MVP-VB - http://www.vbsight.com DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Sign up now to help keep VB support alive - http://classicvb.org/petition Please keep all discussions in the groups.. > Private Declare Function ShowWindow Lib "user32" _ This would work IF the form is loaded, right. Its not even loading the form.> (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long > > Public Sub ShowForm(State As ShowWinStates) > Call ShowWindow(Me.hWnd, State) > End Sub > '=========== Take a loot at this code which is in a module: Public Sub DisplayForm() Load Form1 Form1.ShowWindow( whatever ) End Sub After compiling the standard DLL and calling this sub from another compiled exe, it gives error "ActiveX component cant create object" when the flow reaches 'Load Form1'. Its not even loading it. Cant forms be added to standard DLLs created in VB (using vbAdvance) ? Faraz Azhar |
|||||||||||||||||||||||