From tom.mccallum at levelelimited.com  Tue Nov 21 18:30:56 2006
From: tom.mccallum at levelelimited.com (Tom McCallum)
Date: Tue, 21 Nov 2006 17:30:56 -0000
Subject: [Rd] dyn.load
Message-ID: <op.tjdmxuzoffxks9@norisk>

Hi everyone,

Now I know there is information on this in the help files - which I have  
read.  I am very close to implementing this but can't quite get how to  
remove this final hurdle.

I have a DLL called "X.DLL" which I have no original code for, just the  
DLL.
I have created a wrapper C file for the calls in X.DLL, and have  
successfully (I think) created a wrapper DLL for X called, lets say,  
WRAPX.DLL.

On performing:

> dyn.load("WRAPX.dll")

in the Rgui terminal, I then received this warning:

Warning message:
DLL attempted to change FPU control word from 8001f to 9001f

Getting rid of this error was part of the reason for writing WRAPX.DLL, as  
X.DLL seems to play about with this register.

So having another look at the manual entry, I then used the function  
Rwin_fpset() (in gnuwin32/extra.c) to reset the FPU control register when  
I leave all the functions in WRAPX.DLL.  But the problem persists.  In the  
Delphi example in the manual, which I have put at the end of this message,  
( and I have never programmed in Delphi before so I am guessing ) there is  
the opportunity on loading the dynamic library to set this register, but I  
am wondering where in the C file I can put this command so that when  
dyn.load is called it is not upset by X.DLL changing this register.  I  
think I need the following passage of play to occur:
	
USER		: > dyn.load("WRAPX.DLL");
R   		: Calls WRAPX.DLL
WRAPX.DLL   : WRAPX.DLL initialises X.DLL which interferes with FPU  
register
WRAPX.DLL	: Calls Rwin_fpset() to reset FPU register
R		: R tests FPU register and is happy
USER		: Sees "Success library is loaded!" or something to that effect :)

Any ideas on how to achieve this?

Many thanks

Tom

====DELPHI CODE=====

procedure Rwin_fpset; cdecl; external 'R.dll';

function Get8087CW:word;
begin
   asm
     fstcw result
   end;
end;

begin
   Rwin_fpset();  <============== these lines I think is called on loading  
of the DLL to reset the register
   Set8087CW(Get8087CW); <========
end.

===END DELPHI CODE=====



--
Dr. Thomas McCallum
Systems Architect,
Level E Limited
ETTC, The King's Buildings
Mayfield Road,
Edinburgh EH9 3JL, UK
Work  +44 (0) 131 472 4813
Fax:  +44 (0) 131 472 4719
http://www.levelelimited.com
Email: tom at levelelimited.com

Level E is a limited company incorporated in Scotland. The c...{{dropped}}



[Rd] dyn.load
Tom McCallum