This question is going to be poorly-posed, but I'm spinning my wheels big-time, and I'm not sure how to express it better.
I need to write a DLL, using C, which is to be called from VB6. I'm using Visual Studio Express 2013. I know...VB6 is ancient, and I think the managers of the code are now convinced they should junk it. But in the meantime, this needs to be done.
To start, I am trying to write a DLL with a single function that does nothing but print a message, and that works fine when calling the DLL using VB.NET.
Here's what I have for TinyDll.h.
#ifdef TINYDLL_EXPORTS
#define TINYDLL_API __declspec(dllexport)
#else
#define TINYDLL_API __declspec(dllimport)
#endif
extern TINYDLL_API void __stdcall testdll();
And here's TinyDll.cpp
#include "stdafx.h"
#include "TinyDll.h"
#include <stdexcept>
using namespace std;
void __stdcall testdll()
{
printf("Got into the dll.\n");
}
Incidentally, I've tried this with and without __stdcall. I also tried using a .def file to de-mangle the name in the dll, but it's not clear to me now that should work. The examples I've found indicate that this should work
LIBRARY TinyDll
Exports
testdll
but it does not. The name in the dll is still in mangled form: ?testdll@@YGXXZ.
My test code is fairly trivial, and it works perfectly with VB.NET, but it won't work with VB6. The problem has something to do with the VB6 process not being able to find the dll and/or find the functions inside of it. For the record, here's the VB6 code being used to test
Declare Sub testdll Lib "TinyDll.dll" Alias "?testdll@@YGXXZ" ()
Sub Main()
testdll()
End Sub
First, am I correct that it is not necessary to call regsvr32 or regasm? The dll is not a COM object -- VB6 is calling my C code, not the other way around. When we try to do either of these two things, either "the entry-point DllRegisterServer was not found" or "The specified module could not be found."
To top it off, the VB6 development environment is too old to run on my Windows 7 machine and the person who is trying to test my DLL is in another state and is strictly a VB programmer.
I've read everything I can find by googling, so I'm hoping that someone knows of a website that clearly lays out the facts or shows a working example.
extern "C"
to suppress that? – Notlikethat