TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: JOHN DUMAS
date: 1998-02-04 20:01:00
subject: DLL GOOD STUFF

I have been a pest to a lot of conferences and would like to share
 the results as simply as possible of what I have found.
I have run across so many trying to pass their C code to other
  languages as I have been.
Since strings are the hardest of the normal data types. 
Example of sending and returning a VB string to a C DLL: 
**********************************************************************
'Visual Basic VERSION 4.00
'FORM 1.FRM
1  Private Declare Function GETSTRING Lib "d:\strdll.dll"
2  (ByVal string2send As String) As String
3  Private Sub Command1_Click()
4  string2send = String(255, vbNullChar)
5  returnedstring = String(255, vbNullChar)
6  string2send = "whatever text"
7  returnedstring = GETSTRING(string2send)
8  End Sub
**********************************************************************
/* d:\strdll.dll 
   target as win16 DLL OLE2 ON */
#include 
#include 
#include 
9 extern "C"
  {
10  char * __far PASCAL __export GetString( char __far *RecievedString );
  };
11 char * __far PASCAL __export GetString( char __far *RecievedString )
  {
12   strrev(RecievedString);
13   return(RecievedString);
  };
************************************************************************
notes:
  1+2   Should be on same line but I broke it to fit on page.
  
  1     "Private" needed will not accept otherwise.
  
  1     "d:\strdll.dll" make sure dll can be found single "\" in VB 
  
  1+10  "GETSTRING" changed to "all caps" in DLL so its called that way  
  
  2     "ByVal" when sending string is sending a pointer
        "ByRef" would send a double pointer "VERY TRICKY"
  
  4+5   Space must be reserved "over runs do cause problems"
  
  6     Text to be sent.
  
  7     Function is called.
  
  7     String is returned also since pointer is sent "string2send"
        is also changed.
  
  9     Keeps name from being mangled. actually just adds a few characters.
        but its enough to make it unrecognizable.
  
 10     C declare function here goes:
        return a far character string pointer from a Pascal type exported
        function named GetString which refers a far character pointer to
        a string.
        On a sesame seed bun.
 
 12     String Reverse the string "ABC" becomes "CBA". "BORLAND function"
        Substitute whatever you want but most compilers have strrev.
 
 13     Send back string.             
*************************************************************************
Please feel free to use, rip this apart, add comments,
and send me comments johnjd@worldnet.att.com
... If you think you're confused now, just wait until I explain it.
--- Blue Wave/DOS v2.20 [NR]
---------------
* Origin: The Witch City BBS *Salem,MA [978]745-1689 *Hayes 28.8 (1:101/301)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.