This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

cygwin DLLs and VC


  I've tried compiling a working VC++ DLL project
using the dllhelpers r2.4 provided with Cygwin B20,
and found out that despite the result worked fine
with Gygwin's GCC compiled exes, it didn't work at
all with the same exes compiled with VC. 
  In fact, it returns exactly the same adress for
the dll imported function in both cases, but when
calling it from VC it causes a GP fault. The exports
are done using old-fashion .DEF style, so I'm
forcing the calling convention to "C" using the extern
"C" directive, that I think that should be supported
by
both compilers.
  If any of you found this problem or have any idea
about solving it, please let me know.
 
--The DLL code
 
----Try.h

#ifndef _TRY_H
#define _TRY_H
 
 
#include <windows.h>
#include "interfaces/ICommon.h"
 
 
 class Try: public O3D::ICommon
 {
 	int numRef;
 public:
 	// Constructor / Destructor
 	Try()
 	{
 		numRef = 1;
 	}
  
  	// ICommon
  	int Release()
  	{
  		if (!(--numRef))
  			delete this;
  		return numRef;
  	}
  
  	void AddReference()
  	{
  		numRef++;
  	}
  
  	ICommon *GetInterface(int iid)
  	{
  		return this;
  	}
  
  	int GetImplID() const 
  	{
  		return 666;
  	}
  };
  
  
 #endif
  
 ----Try.cpp
  
 #include <stdio.h>
 #include "Try.h"
 
  
 ICommon *Create()
 {
 	return new Try();
 }
  
  
 extern "C" void Register(FARPROC* pSt)
 {
   printf("Registering...\n");
 	*pSt = (FARPROC)Create;
 }
 
 ----Try.def
 
 LIBRARY		Try.dll
 
 EXPORTS
 
 	Register
  
  
 --The exe using the DLL:
  
 #include <stdio.h>
 #include <windows.h>
 

 #include "interfaces/ICommon.h"
  
  
  
 int main(int argc, char *argv[])
 {
    printf("\nLoading library...\n");  
  
 HMODULE hLib;
  
    hLib = LoadLibrary("Try.dll");
  	
 void (* pFunc)(FARPROC*);
  
    pFunc = (void (*)(FARPROC*))GetProcAddress(hLib,
 "Register");
    printf("\npFunc: %x\n", pFunc);
  	
 FARPROC Creat;
  
    pFunc(&Creat);
  
 ICommon* pObj;
  
    pObj = (ICommon*)Creat();
    printf("\nID: %i\n", pObj->GetImplID());
  	
    FreeLibrary(hLib);	
    return 0;
 }
  
  
    Thanks for reading this.
  
      Tony Sanchez

__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]