[Rd] (PR#4806)

L.T.Kell at cefas.co.uk L.T.Kell at cefas.co.uk
Mon Oct 27 16:38:44 MET 2003


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_000_01C39C9F.B5DABBD0
Content-Type: text/plain;
	charset="iso-8859-1"

# Your mailer is set to "none" (default on Windows),
# hence we cannot send the bug report directly from R.
# Please copy the bug report (after finishing it) to
# your favorite email program and send it to
#
#       r-bugs at r-project.org
#
######################################################



I am trying to call functions written in Visual C++ from R version 1.8.0
under Windows. 
Although these functions ran correctly in version 1.7 in Version 1.8.0 they
cause R to crash after the function has returned to R

I can repeat the problem with a DLL based on a simple example given by
Douglas Bates. 

dyn.load("TestDll.dll")
test<-function(x,y) .Call("out",x,y)

x<-1:10
y<-2:10
test(x,y)

The C++ code is below

#include <windows.h>
#include <R.h>
#include <Rinternals.h>


HWND      hWndMain;   
HINSTANCE hInst;    
HGLOBAL   hXloperArray;

//32 bit Entry point

#define CLASS_NAME_BUFFER  50

BOOL WINAPI DllMain(HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
   {					
   extern HWND      hWndMain;
   extern HINSTANCE hInst;    
   
   hInst = hDLL; 
    
   return TRUE;
   }

extern "C" int FAR PASCAL WEP (int nArgument)
   {
   return 1;
   } 
     
extern "C" __declspec(dllexport) SEXP __stdcall out(SEXP x, SEXP y)
     {
       int i, j, nx, ny;
       double tmp;
       SEXP ans;
     
       nx = length(x); ny = length(y);
       PROTECT(ans = allocMatrix(REALSXP, nx, ny));
       for(i = 0; i < nx; i++) {
         tmp = REAL(x)[i];
         for(j = 0; j < ny; j++)
           REAL(ans)[i + nx*j] = tmp * REAL(y)[j];
       }
       UNPROTECT(1);
       return(ans);
     }
     


I created the lib file from the R.dll using pexports and lib
i.e.

pexports R.dll > RDLL.def
lib /machine:i386 /def:RDLL.def /out:Rdll.lib

Used the following def file

LIBRARY   TestDLL	
EXPORTS	
   out		       =_out at 8

Regards Laurie

--please do not edit the information below--

Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status = 
 major = 1
 minor = 8.0
 year = 2003
 month = 10
 day = 08
 language = R

Windows 2000 Professional (build 2195) Service Pack 3.0

Search Path:
 .GlobalEnv, package:methods, package:ctest, package:mva, package:modreg,
package:nls, package:ts, Autoloads, package:base


 <<Laurence Kell (E-mail).vcf>> 

------_=_NextPart_000_01C39C9F.B5DABBD0
Content-Type: application/octet-stream;
	name="Laurence Kell (E-mail).vcf"
Content-Disposition: attachment;
	filename="Laurence Kell (E-mail).vcf"

BEGIN:VCARD
VERSION:2.1
N:Kell;Laurence
FN:Laurence Kell (E-mail)
ORG:CEFAS
TEL;WORK;VOICE:+44 (0) 1502 524257
TEL;WORK;FAX:+44 (0) 1502 524511
ADR;WORK:;;Lowestoft Laboratory;Pakefield Road;Lowestoft,;NR33 0HT;UK
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:Lowestoft Laboratory=0D=0APakefield Road, Lowestoft, NR33 0HT=0D=0AUK
EMAIL;PREF;INTERNET:/o=CEFAS/ou=LOWESTOFT/cn=Recipients/cn=LTK00
REV:20030410T130517Z
END:VCARD

------_=_NextPart_000_01C39C9F.B5DABBD0--



More information about the R-devel mailing list