delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/03/16/10:41:11

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Message-ID: <20000316154018.8752.qmail@web121.yahoomail.com>
Date: Thu, 16 Mar 2000 07:40:18 -0800 (PST)
From: Incubus "Incógnita" <icg_incubus AT yahoo DOT com>
Subject: cygwin DLLs and VC
To: cygwin AT sourceware DOT cygnus DOT com
MIME-Version: 1.0

  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 AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019