Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't register DLL

Status
Not open for further replies.

mrgary

Programmer
Dec 16, 2000
2
0
0
US
I am having difficulty registering a DLL written in Visual C++ 6.0. Here is the code:

#include <windows.h>
#include <io.h>

extern &quot;C&quot; _declspec(dllexport) char *SubString();


char *SubString()
{
char test[15] = &quot;hello trident!&quot;;
return test;
}

It is just a test. I just want to get the framewoek correct before proceeding. The dll will be used by VB.

Error message when using regsrvr32:

DLL registerserver entry point not found.

Any ideas what I should do?

gary
 
> Any ideas what I should do?

Sure, Regsvr32.exe's code is on MSDN for download and contains these lines of code:

// Find the entry point.
(FARPROC&amp;)lpDllEntryPoint = GetProcAddress(hLib,
_T(“DllRegisterServer”));


So that is why the error message states:

> DLL registerserver entry point not found.

-pete
 
Try this:


HINSTANCE h = LoadLibrary( &quot;xxxxxx.DLL&quot; );
if ( h == NULL )
{
AfxMessageBox( &quot;unable to load 'xxxxxx.DLL'.&quot; );
return;
}

typedef int ( *REG ) ( void );
REG f_reg = ( REG ) GetProcAddress( h , &quot;DllRegisterServer&quot; );

if ( f_reg == NULL )
{
FreeLibrary( h );
AfxMessageBox( &quot;unable to load 'DllRegisterServer' in 'xxxxxxx.DLL'.&quot; );
return;
}

f_reg();

FreeLibrary( h );
 
There is two variants:
//variant 1
extern &quot;C&quot; _declspec(dllexport) char *SubString();
extern &quot;C&quot; char *SubString()
{
char test[15] = &quot;hello trident!&quot;;
return test;
}
//variant 2
_declspec(dllexport) char *SubString();
char *SubString()
{
char test[15] = &quot;hello trident!&quot;;
return test;
}
--------
The second variant you can call only from a c++ program generated by the same compiller what generated the dll.
 
Thanks for your help... but regsvr32 fails on variant #1. I need to call this DLL from Visual Basic.
 
VB do not use NULL terminated string. Try to use bstring(BSTR) instead of char*
 
mrgary -

Registering DLLs only works when they are COM DLLs. An ordinary C/C++ DLL doesn't require this.

In your case, put your DLL where your VB app can find it (application directory or System32), then in your VB code include the correct declare statement, something like:
[tt]
Private Declare Function SubString Lib &quot;mrgary.dll&quot; () As String
[/tt]

There may be some Unicode issues if your DLL has the _MBCS flag set in your project settings.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top