Drew Wutka
DWUTKA at marlow.com
Mon Mar 3 13:56:38 CST 2003
It only took a few minutes to write that .exe, so it wasn't exactly a 'huge' project. It boils down to requiring the same amount of work in the end. My co-worker just lives for using regsvr32.exe, and I just out of habit run my .exe. 6 here, half dozen there. ;) Drew -----Original Message----- From: Jim DeMarco [mailto:Jdemarco at hshhp.org] Sent: Monday, March 03, 2003 11:55 AM To: dba-vb at databaseadvisors.com Subject: RE: [dba-VB] RE: Web Activex DLL's Drew Do you really need to write an app to register a DLL? You can add an item to the Windows Send To menu that's a shortcut to regsvr32.exe (right click a DLL, choose Send To | Register a DLL, or whatever you named the shortcut). Unless there's some functionality I'm missing here. Hadyn's request is actually timely as I've been working on a demo/tutorial/mini-training session for our developers to acclimate them to ASP via straight ASP, VB, and finally .NET. It will probably be complete by the end of the week (or early next week) and if anyone would like to see it I'd be glad to entertain off-line requests. Basically I wrote a few simple pages in ASP, duplicate them in VB and VB.NET just to show the method. It's really a simple tutorial that shows how to look up and display data, and do data entry via the web. Thanks, Jim DeMarco Director of Product Development HealthSource/Hudson Health Plan -----Original Message----- From: Drew Wutka [mailto:DWUTKA at marlow.com] Sent: Monday, March 03, 2003 12:23 PM To: 'Hadyn Morgan' Cc: dba-vb at databaseadvisors.com Subject: [dba-VB] RE: Web Activex DLL's Hadyn, I am cross posting this to the VB list, because there's going to be some good info in here. First of all, to create a .dll in VB, you are using Class modules. I have an example here, which shows how to use Classes and Collections within Access 97 (I actually wrote the code in VB and copied it to Access). http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Cat=&Board=acc&Number=216645 &page=&view=&sb=&o=&vc=1#Post216645 Let me know if you want specific code examples. I am just going to give some of the in's and out's with this email/post. First of all, when you create a .dll in VB, you'll need to 'register' it on your IIS server. Open VB, and create a new Advanced Project. (Should be the last type of project.). Leave the form as Form1, and add a commondialog control to the form. Then put this code into a module: Public Declare Function DLLSelfRegister Lib "vb6stkit.dll" (ByVal lpDllName As String) As Integer Sub Main() Form1.CommonDialog1.Filter = "Dynamic Link Libraries | *.dll" Form1.CommonDialog1.DialogTitle = "What Dynamic Link Library do you want to register?" Form1.CommonDialog1.ShowOpen Dim dwReturn As Long dwReturn = DLLSelfRegister(Form1.CommonDialog1.FileName) If dwReturn = 0 Then MsgBox ".dll has been registered", vbOKOnly + vbInformation, "Success" Else MsgBox "System Failed to register the .dll for the following reason:" & _ vbCrLf & vbCrLf & fGetMessage(dwReturn), vbOKOnly + vbExclamation, "Failure" End If End End Sub Save this module, and put this code in another module: Public Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000 Function fGetMessage(msgNum As Long) As String Dim strTemp As String Dim i strTemp = Space(500) i = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, "", msgNum, 0, strTemp, 500, 0) fGetMessage = Left(strTemp, InStr(1, strTemp, Chr(0), vbBinaryCompare) - 1) End Function Save your project, and compile the .exe. You know have a VERY simple way to register your ActiveX .dll's. Just run the .exe on your IIS server. A few things to note about registering your .dll's. First of all, the server will need the necessary runtimes. So you'll need to install some VB program at some point, for the .dll's to even work at the basic level. Also, you'll need addition runtimes for whatever your using. For instance, you'll need MDAC installed, if you are going to use ADO. (I have a few 'programs' that have 99% of the drivers I am ever going to use, and I just install one of them, then I can just use the register program above to 'register' my ActiveX .dlls. Next, when do you need to 're-register' your .dll's? If you Add a new class, you have to re-register the .dll. That is because the 'registration' process learns what objects are in your .dll to use, so if you add a new class, recompile, and copy it to your IIS server, your ASP programs will not pick up the new class (it will just give you an error). Running the registering program again fixes that. Also, this is a quirk I noticed, if you compile a .dll from one machine, and register it on the IIS server. Then compile the same .dll on a second machine, you will have to re-register the compiles from the second machine no matter what you change. It has to do with the GUID that is assigned to the .dll, when you compile it. I have never bothered to figure out more then that! <grin> When you actually want to use your .dll in ASP, you must use CreateObject, however, in ASP you must use the CreateObject method of the Server object. ie: Dim cnn Set cnn=server.createobject("ADODB.Connection") or for a personal .dll Dim myClass Set myClass=server.createobject("MyProject.MyClass") Finally, my last tip is to take the extra time to make all of your classes as true owners of what they represent. For example, in my 'example' project linked above, I have a 'lone' data class, which holds data on a particular 'object'. That class can be used to pull up the information by key, or it can be set to just hold the information, and it can also be used to save information (for a new object, or for modifying an existing object). Then I have a 'collection' class, that builds a collection of existing objects. By have the single object class designed to be 'self contained', even if I only ever use it in the collections class (which fills the data in for each new instance of the single class), the ability to pull up an item individually is still there, or to modify that object, etc. Abilities that make things easy as a project is expanded (as they tend to do.). Hope this helps some. Drew -----Original Message----- From: Hadyn Morgan [mailto:hadyn at dataconcepts.co.nz] Sent: Saturday, March 01, 2003 8:36 PM To: Drew Wutka Subject: Web Activex DLL's Hi Drew I thought I remembered you saying that you write your own DLL's for your web projects, so... I am just starting a new web project (online order/quote system) that has a number of complicated processes. I thought the best way to handle this would be through a DLL or two via ASP. I have not created DLL's before and wondered if you could give me a few tips/pointers on where to start :) I have VB 6 (VS) and IIS 5.1 installed. Kind regards Hadyn ___________________________________________ DATA CONCEPTS LTD Enhancing Your Information Management PO Box 1154, Hamilton 2001, New Zealand Tel +64 7 855 9308 Mob +64 21 124 4488 Email: hadyn at dataconcepts.co.nz Web: http://www.dataconcepts.co.nz _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com **************************************************************************** ******* "This electronic message is intended to be for the use only of the named recipient, and may contain information from HealthSource/Hudson Health Plan (HS/HHP) that is confidential or privileged. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or use of the contents of this message is strictly prohibited. If you have received this message in error or are not the named recipient, please notify us immediately, either by contacting the sender at the electronic mail address noted above or calling HS/HHP at (914) 631-1611. If you are not the intended recipient, please do not forward this email to anyone, and delete and destroy all copies of this message. Thank You". **************************************************************************** ******* _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com