473,327 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Creating VB.Net ActiveX / COM Wrapper DLL from C Library for use in ASP script

I'm looking for a simple but complete example of creating a VB.Net
ActiveX / COM component from a C Library. One should be able to use it
by calling the Server.CreateObject method from an ASP script. I have
already figured out how to do most of it, but I'm stumped on the part
where I call it from an ASP script.

Assume I have a VS.Net solution with three projects:

1. CLibrary - generates a DLL from the following C source code:

extern __declspec(dllexport) int authenticate_user(char *login, char
*password);

extern __declspec(dllexport) int authenticate_user(
char *login, char *password) {
return strcmp(login,password); // just compare the username and
password for demo purposes
}

then

2. ComClass - a VB.NET class that uses DLLImport to call the CLibrary.
I have enabled Interop in the project settings. Here's the source:

Public Class Class1
<DllImport("CLibrary.DLL", EntryPoint:="authenticate_user", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function
AuthenticateUser(<MarshalAs(UnmanagedType.LPStr)> ByVal Username As
String, <MarshalAs(UnmanagedType.LPStr)> ByVal Password As String) As
Int16
End Function
End Class

3. The above projects compile fine and work correctly if I call them
from a third project, ConsoleApplication1, a VB.NET Console
Application, which references ComClass:

Sub Main()
Dim objCom As New ComClass.Class1
Dim Username As String
Dim Password As String
Do Until False
Console.Write("Username: ")
Username = Console.ReadLine()
If Username = "" Then
Exit Do
End If
Console.Write("Password: ")
Password = Console.ReadLine
Console.WriteLine(objCom.AuthenticateUser(Username ,
Password))
Loop
objCom = Nothing
End Sub

the above works. However, I have two questions/concerns:

1. Any time I change the C Library, I have to physically copy the DLL
generated from CLibrary to the bin directory of the ConsoleApplciation
application. I would prefer to simply reference it in the
ConsoleApplication or ComClass project, but it won't let me do that
since it's not a .NET Assembly. Is there any way to automate that step?

2. I need to call ComClass from an ASP script. I tried using
RegSvr32.exe to register it but it tells me it can't find the
DLLRegisterServer entry point. How do I create a DLLRegisterServer
entry point, or is there a different way to register it? I'd like to be
able to call it via code such as:

sUsername = Request("Username")
sPassword = Request("Password")
Set oComClass = Server.CreateObject("ComClass.ComClass")
iResult = oComClass.AuthenticateUser(sUsername, sPassword)
Set oComClass = Nothing
Response.Write ("Result: " & iResult)

What do I need to do to be able to use the class from an ASP script?

Nov 22 '05 #1
0 1850

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Steve | last post by:
Can anyone point me to a primer for creating OCX controls in VB .net? In particular, I want to access a web service in a VB6 application (not an easy thing to do). So, if I can write an ActiveX...
2
by: Berata | last post by:
Hello all, in VB6 we were able to create ActiveX-DLL's (In Process Components) and ActiveX-Exe's (Out of Process Components). We habe build up an application that exists of an main module...
0
by: soundchaser | last post by:
I'm looking for a simple but complete example of creating a VB.Net ActiveX / COM component from a C Library. One should be able to use it by calling the Server.CreateObject method from an ASP...
1
by: James Pannozzi | last post by:
I have a C++ App which currently uses #import to access some ActiveX DLL's provided to me from some companies. These desktop ActiveX apps typically have a GUI with a VB form in which the desktop...
1
by: Mehr H | last post by:
I have been working on this for several days and am still have had no success in achieving this. Pleae help. It seems that documentation for this is very limited. I have looked in several books and...
4
by: Stephen | last post by:
Hi I am currently developing a web application that has a third party component on it. The third party component is a graph component from Xceed that uses a number of dlls. The problems occur...
6
by: Steve Richter | last post by:
I am getting error in a vbscript: ActiveX component cant create object: Excel.Application. The vbscript code is: Dim objExcel Set objExcel = CreateObject("Excel.Application") I am pretty...
8
by: Martijn Boven | last post by:
I created a activex control in c# (vs 2005) -------------------------------------------- public partial class ActiveTest : UserControl { public ActiveTest()
23
by: Galen Somerville | last post by:
A VB6 ActiveX.exe raises an event which is seen by the VB6 App. Same setup in VB2005. The event to be raised is in form frmSweep. As in VB6, frmSweep is hidden when the events take place. I...
1
by: kret | last post by:
Hi, this is my first post so first of all I would like to say hello :) Now getting to my problem. In my job I have to create an ActiveX control in .NET 1.1 that can be lunched from IE....
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.