Calling a .Net dll from Visual basic

dotnet framework


  • 1. failed call to marshal.getactiveobject causes mmc and explorer.exe to crash
    I use com object interop to automate adobe illustrator cs 5. To know if illustrator is up and running I use getactiveobject. After this call has failed (ai not running) with an exception, it seems that all windows 2008 server .net application (e.g. mmc snapins, explorer.exe etc) gets really unstable. example any right click on a file or folder causes appcrash. Anyone experienced this?
  • 2. .NET coclass has multiple dispinterfaces
    Hi! I've got a COM Interop library written in C#, .NET 2.0. This library exposes a COM class which implements two interfaces, one interface comes from an imported VB6 class library (CHelloWorld) and another is declared in C# itself (CExtendedHello). If I attempt to use this COM class via late binding (IDispatch) in VB6, the following happens: Dim o As Object Set o = CreateObject("ManagedInteropHello.CExtendedHello") Call o.Hello ' Doesn't work! Call o.HelloUser("TestApplication") I can only call the HelloUser() method that is in the default interface of the class. But watch what happens if cast this class to CHelloWorld and back: Dim hw As HelloWorldLib.CHelloWorld Set hw = o Set o = hw Call o.Hello Call o.HelloUser("TestApplication") ' Doesn't work! Now the Hello() method from the CHelloWorld interface works and the HelloUser() method from the default interface ceases to exist. Its as if there were two completely seperate IDispatch interfaces for the class. Can someone explain this? What I'm trying to do is give the class a single IDispatch interface that contains all methods of all interfaces. -Markus-

Calling a .Net dll from Visual basic

Postby ford_desperado » Thu, 18 Nov 2004 08:45:17 GMT


I've created a .Net dll, and wrapped it in CCW:

using System.Runtime.InteropServices;

namespace XMLUpload

	public class XMLUploadBase


then I built the dll and registered it no problem:
regasm "full path / dll name"

regasm said that "types registered successfully"

Then I vcreated a VB project in MS VIsual Basic 6.0 (sp5) and tried to
add the dll to References. The dll was not listed, so I browsed to the
dll, but instead of registering I got 'Can't add a reference to the
specified file'

what am I missing?


RE: Calling a .Net dll from Visual basic

Postby S2F1c3Rhdg » Thu, 18 Nov 2004 16:55:02 GMT


add the following attribute to the public class 

You can generate a GUID from VS.NET IDE -> Tools -> Create GUID

Also register your project for COM Interop from Project properties.



Re: Calling a .Net dll from Visual basic

Postby ford_desperado » Sat, 20 Nov 2004 07:50:11 GMT

thank you Kaustav, that worked

Similar Threads:

1.Visual C++ calling Visual Basic DLL

2.Problem calling dll function with Visual Basic

I'm using Access Visual Basic.
When trying to call this function within its class module:
    Declare Function DAZOptions Lib "emdaz32.dll" (ByVal lngHandle As Long) 
As Long

I receive the following error:
    Run time error '53':
        File not found: emdaz32.dll

My code and this function worked perfectly with Windows XP but now fails 
after upgrading to Windows Vista 64-bit.

The file emdaz32.dll IS contained in the folder C:\Windows\System32\.

Even if I declare the function using the full path to the dll file as shown 
    Declare Function DAZOptions Lib " C:\Windows\System32\emdaz32.dll" 
(ByVal lngHandle As Long) As Long

I still receive the same error message just showing the full path:
    Run time error '53':
        File not found: C:\Windows\System32\emdaz32.dll

I don't understand why "File not found" error is returned when the file is 
Is there something different I have to do to call a 32-bit dll when using 
Windows Vista 64-bit version?  My other 32-bit applications are working 

I will GREATLY appreciate any assistance anyone can offer.  This has me 
really stumped and frustrated.

3.Trying to use GetProcAddress to call a function in a DLL using Visual Basic

I am trying to get my VB code to work on 32 bit Windows and 64 bit

I am trying to call a pointer to function that resides in a DLL using
the GetProcAddress and then call the function through the pointer.

See Below Code:

Attribute VB_Name = "IsWin64"
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA"
(ByVal lpLibFileName As String) As Long Declare Function FreeLibrary
Lib "kernel32" (ByVal hLibModule As Long) As Long Declare Function
GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName
As String) As Long

Function Is64BitWindows() As Boolean
Dim r2 As Long
Dim hLib As Long
Dim fpFunction As Long

' Load up Kernel32.Dll
hLib = LoadLibrary(Environ("WINDIR") + "\system32\kernel32.dll")

' If we were able to load it up
If hLib Then

    ' Try to load up a pointer to the routine
    fpFunction = GetProcAddress(hLib, "IsWow64Process")
    ' How do I call fpFunction() ?

    FreeLibrary Lib

End If

End Function

Sub Main()

bRet = Is64BitWindows()

End Sub

4.C/C++ calling via COM ActiveX Visual Basic DLL

I created an ActiveX DLL written in Visual Basic.
I have no problem linking to dll from VB test driver.
I have no problem linking from C/C++ test driver.
I am having problems connecting to it from an NT Service.
The NT service also monitors an Exchange Mailbox so it is 
linking to the MAPI functions.

When The program calls CoInitialize or CoInitializeEx,
the same result occurs.  When it attempts to link to the 
DLL, it is returning an error.  The error is 80004003 
(invalid pointer).

Any information will be appreciated.

5.Calling visual basic dll from excel vba

6. DLL called from Visual Basic

7. Calling a DLL from Visual Basic 6.0

8. calling LV DLL or EXE from Visual Basic with return values

Return to dotnet framework


Who is online

Users browsing this forum: No registered users and 82 guest