home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / mswindo / programm / misc / 4609 < prev    next >
Encoding:
Text File  |  1993-01-05  |  2.0 KB  |  69 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!infonode!ingr!msdhsv!norooz!ahmad
  3. From: ahmad@norooz.NoSubdomain.NoDomain (Ahmad Alavi)
  4. Subject: DLL problem (using BC++/AF)
  5. Message-ID: <1993Jan5.212008.6162@msdhsv.ingr.com>
  6. Sender: usenet@msdhsv.ingr.com (USENET)
  7. Reply-To: ahmad@norooz.b17a.ingr.com
  8. Organization: " "
  9. Date: Tue, 5 Jan 1993 21:20:08 GMT
  10. Lines: 57
  11.  
  12.  
  13. I have problem calling a routine in a DLL when the DLL is loaded
  14. using LoadLibrary.
  15.  
  16. Here is the DLL source code in its entirely.
  17.  
  18.     #include <windows.h>
  19.     int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
  20.                                    WORD wHeapSize, LPSTR lpszCmdLine )
  21.     {
  22.         if ( wHeapSize != 0 )
  23.             UnlockData( 0 );
  24.         return 1;
  25.     }
  26.  
  27.     BOOL FAR PASCAL MyFunction (char far *theString) /* this functions is */
  28.     {                                            /* exported in .DEF */
  29.          return 1;
  30.     }
  31.  
  32.  
  33. And the main executable source:
  34.  
  35.     #include <owl.h>
  36.     int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  37.                        LPSTR lpCmdLine, int nCmdShow)
  38.     {
  39.         HINSTANCE DLLInstance;
  40.         BOOL FAR (*MyFunctionFunc)(char far  *theString);
  41.         DLLInstance = LoadLibrary("dll1.dll");
  42.         (FARPROC) MyFunctionFunc =GetProcAddress(DLLInstance, "MyFunction");
  43.         (*MyFunctionFunc)("In the MAIN");
  44.         FreeLibrary(DLLInstance);
  45.  
  46.         TApplication MyApp("Sample Program", hInstance, hPrevInstance,
  47.                lpCmdLine, nCmdShow);
  48.         MyApp.Run();
  49.         return MyApp.Status;
  50.     }
  51.  
  52. When I run the main program, everything looks OK and MyFunction in DLL
  53. is actually called but I get a General Protection Fault. The error happens
  54. inside MyApp.Run() call. If I change MyFunction argument to int the
  55. there is no problem (but I really need it to be char*).
  56.  
  57. I have a short term and long term question.
  58.  
  59. STQ: What is wrong with the above programs?
  60. LTQ: What is a good refrence book for DLL programming?
  61.  
  62. Post or mail.
  63.  
  64. Thanks.
  65.  
  66. Ahmad
  67. ahmad@norooz.b17a.ingr.com
  68.  
  69.