CompuServe Thread

#BAD DLL CALLING CONVENT.

8 messages in this thread
#1224From: Don FunkOct 3, 1991 5:23 PM
Hi Alfred, I was able to do this. Here is my code that did it. Is there something that I don't see that you are doing diferently? Don Funk ======================= VB Declare Function ReturnDouble Lib "c:\avb\dll\mydll.dll" () As Double Sub Form_Click () Print ReturnDouble() End Sub ======================= MyDll.c #include <WINDOWS.H> double FAR PASCAL ReturnDouble(); int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize) { if (wHeapSize > 0) UnlockData(0); return 1; } int FAR PASCAL WEP(int iParam) { return 1; } double FAR PASCAL ReturnDouble() { return (double)1; } ==========MyDll.def LIBRARY MYDLL EXETYPE WINDOWS PROTMODE CODE PRELOAD MOVEABLE DISCARDABLE DATA PRELOAD SINGLE HEAPSIZE 1024 EXPORTS WEP @1 RESIDENTNAME ReturnDouble @2 There is 1 Reply.
#1257From: Jonathan Zuck (UFI)Oct 3, 1991 8:26 PM
Don, What you don't see is that MSC (both on the VB end and the DLL end) is making use of a hidden final parameter which is the address of the double that should be returned. BC++ is not aware of this and blows up. -=Jonathan
#1281From: John RuzickaOct 3, 1991 11:51 PM
Sorry for butting into this thread, but I have been unable to get VIsual Basic to recognize a function in a DLL, and others have been unable to help me. Everyone in this message seems to have at least gotten BC++ and VB to "cooperate." I compiled a DLL, using "all functions exportable," and containing a function called "Chowmain" that returns an int. IN BC++ I have the following: extern "C" int Chowmain(void); .. WinMain here … extern "C" int Chowmain(void) { return 1; } IN VB, global module, I tried: Declare Function Chowmain Lib "john.dll" () and Declare Function Chowmain Lib "john.dll" Alias "_chowmain" () (not at the same time) I keep getting a Sub or Function Not Found message from VB. I have tried virtually every combination of extern _export, etc., but obviously am still not using the right one 🙂 Can anyone give me some help or a simple example of how to call a BC++ function from VB? Thanks, John Again, sorry for interrupting There is 1 Reply.
#1301From: Jonathan Zuck (UFI)Oct 4, 1991 2:29 AM
John, Zip it up and send it over. I may be able to figure out what's the matter. BC++ often mangles the function names but the "C" keyword should probably have gotten rid of that problem -=- Jonathan There are 2 Replies.
#1352From: John RuzickaOct 4, 1991 10:42 AM
THanks for the help, actually, no need to zip the code–it's short. I was just playing to see if I could do it. Here's the Code BC++ ————#include <stdio.h> #include <windows.h> extern "C" int Chowmain(void); int FAR PASCAL LibMain(HANDLE One,WORD Two,WORD Three,LPSTR Four) { return 1; } int Chowmain(void) { return 1; } VB GLOBAL FILE ———Declare Function Chowmain Lib "d:\vb\john.dll" I also tried Declare Function Chowmain Lib "d:\vb\john.dll" Alias "_Chowmain" () (parents should be after first declaration, too). In addition, in CPP source file, I used _export before function name, and also tried using 'extern "C" int FAR PASCAL Libmain…' Thanks, John There is 1 Reply.
#1581From: Jonathan Zuck (UFI)Oct 5, 1991 11:44 PM
John, I will take this over to the machine where BC++ is running. Everything *looks* fine on the surface but you never know. -=- Jonathan
#1408From: John RuzickaOct 4, 1991 4:07 PM
Jonathan, Disregard the last message. With help from everyone here, particularly Mr. Chen, I was able to get it to work. I was missing the FAR PASCAL identifier. One last question, how do I return a string to a VB progra when C has no string data type. I tried returning a char * and got an UNRECOVERABLE APPLICATION ERROR. Thanks, John There is 1 Reply.
#1585From: Jonathan Zuck (UFI)Oct 5, 1991 11:45 PM
John, I'm glad you got things working. I saw the FAR PASCAL bit but I was going to go back into BC++ to be sure before humiliating myself publicly. As for your second question, I can help. I need to create a string function for the VBPOINT.DLL that I just uploaded. To accomplish this, you need the CDK. There is a function VBCreateHlStr that creates a VB string and copies a specified number of characters into it from a buffer to supply. This functio returns a "handle" to a VB string and *that* is what you return as your string function. The CDK is pretty cheap but if you don't want to deal with it, you could simply download VBPTR.ZIP and call the function there. You pass the *char and the number of bytes and you would get a LONG back. You would then return this LONG as your function result. Make sense? -=- Jonathan