Click to See Complete Forum and Search --> : Connecting to C++ again
Sam Finch
Apr 27th, 2000, 12:29 AM
Yes.
I have absolutley no Idea where to go from there, I learnt C++ from the complete Idiots guide to C++ and I only know how to do console mode apps, but I know enough about the API to do everything I need in the functions, I've tested the functions from a bit of a consolemode front end and they work (as far as I can tell, I didn't bother putting the graphics out to the screen)
I need it as a dll as I pass out pointers an use callback functions can I pass out pointers in a staticly linked app (obviously I can but can I get at the memory).
rchiav
Apr 27th, 2000, 01:07 AM
if you're using VC then you'd use the wizard to make a dll.. in order to get at the functions in your dll, you have to export them. Here's some info on that...
MFC DLL -
http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_core_overview.3a_.creating_an_mfc_dll.htm
C DLL -
http://msdn.microsoft.com/library/officedev/office97/SF7E6.htm
You'd refrence them in VB the same way you refrence any other DLL call. like...
<from VB5 help>
Declare Sub MessageBeep Lib "User32" (ByVal N As Long)
you're saying that MessageBeep is in lib user32 and it's expecting a long.
Hope that helps..
Sam Finch
Apr 27th, 2000, 02:43 AM
Ok I'm still having trouble, I start up the appwizard and select win32dll, and use a simple DLL, I type my function in like the website said so It looks like this
_declspec(dllexport) long _cdecl myfunc(short factor1,short factor2)
{
return (long)(factor1 * factor2);
}
into the main cpp file and batchbuild so I get a release version.
I declare it in VB and it can't find the file unless I give it the full file extension, when I do this it says that it can't find DLL entry point myfunc.
What do I do? This is really frustrating.
rchiav
Apr 28th, 2000, 10:15 AM
how did you declare it in your vb app?
Sam Finch
Apr 28th, 2000, 07:46 PM
I'm declaring it as I would an API
Private Declare Function myfunc Lib "C:\TestDll\Release\TestDll" (factor1 As Integer, Factor2 As Integer) As Long
I've tried loads of other ways of doing it (C++ side) as well, every source in MSDN does it differently and they all give me the same error.
rchiav
Apr 30th, 2000, 09:10 PM
I think you're missing the actual "EXPORT" part. It does get a little confusing. Here's another article that may help.. though it's more in-depth and may confuse you even more..
http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_core_calling_dll_functions_from_visual_basic_applications.htm
let me know how you make out.
Sam Finch
Apr 30th, 2000, 09:23 PM
Thanks, I think I've seen that but I'll have another look, I think MSDN is just designed to confuse people.
It maybe a type but you are missing an underscore on the __declspec
_declspec(dllexport) long _cdecl myfunc(short factor1,short factor2)
{
return (long)(factor1 * factor2);
}
then depending on what you do inside your function you may have to do:
extern "C"
{
__declspec(...)...
}
and did you do the BOOL WINAPI DllMain?
/*
OK i should have read all of the messages, here is what you do, paste this into a .cpp and compile:
*/
#include<iostream.h>
/*
this is where you enter the dll,
you must have it, and it won't work without it
that's where you get the error message
*/
BOOL WINAPI DllMain(HANDLE HModule, DWORRD ul_reason_for_call, LPVOID lpReserved)
{
switch(ul_reson_for_call)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PRECESS_DETACH:
break;
}
return(TRUE);
/*depending on functions you use*/
extern "C"
{
extern __declspec( dllexport) long myFunctionName(myParameters);
}
long myFunctionName(myParameters)
{
return(10);
}
[Edited by Faust on 05-01-2000 at 04:08 PM]
Sam Finch
May 1st, 2000, 05:52 AM
/*depending on functions you use*/
extern "C"
{
extern __declspec( dllexport) long myFunctionName(myParameters);
}
I missed out that bit, I wish MSDN was good, it should have made it clearer.
I'm assuming this is a bit like the way you declare functions in classes, and that you can overload them and the like, I makes much more sense now thanks.
Mongo
May 1st, 2000, 06:05 AM
Sam,
MSDN Article Q194609 may be of some help to you. It's available at http://msdn.microsoft.com/default.asp (use search on Q194609). Hope it helps.
Sam Finch
May 2nd, 2000, 09:27 PM
OK, I've just about got the hang of it, Thanks a lot for your help.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.