Re: Excel

new topic     » goto parent     » topic index » view thread      » older message » newer message
ne1uno said...
Mike777b said...

Well, it has been another year or so, so I thought I'd try again.

it's been said the quickest way to get an answer from a forum is to first post an incorrect answer.

Must....resist.....

ne1uno said...

could try to translate with -dll option then call myfunction.dll with the VB wrapper.

 
public function MyFunction(atom a, atom b) 
	atom c = a * b 
	return c 
end function   
 
 

I wasn't able to get VB script to link to the dll created this way, but I'm sure it can be done. the translator or eu.cfg doesn't have the ability yet to pass any/all options to the compiler so you may have to edit the default created emake.bat if required.

One issue with this is that he wants to pass a double. Euphoria callbacks can't handle doubles being natively passed. They can only take 31-bit integers (or Euphoria Atoms or Sequences).

The desired signature is:

Public Declare Function MyFunction Lib "c:\MyDLLs\MyDLL.dll" _  
  (ByVal a As Double, ByVal b As Double) As Double  

If you translate (I did this on Linux, but should be similar), you should get some thing like :

$ euc -makefile-full -dll vb.e 
 
// inside vb.c: 
int _1MyFunction(int _a_144, int _b_145) 
{ 
    int _c_146 = 0; 
    int _0, _1, _2; 
     
 
    /** 	atom c = a * b*/ 
    if (IS_ATOM_INT(_a_144) && IS_ATOM_INT(_b_145)) { 
        if (_a_144 == (short)_a_144 && _b_145 <= INT15 && _b_145 >= -INT15) 
        _c_146 = _a_144 * _b_145; 
        else 
        _c_146 = NewDouble(_a_144 * (double)_b_145); 
    } 
    else { 
        if (IS_ATOM_INT(_a_144)) { 
            _c_146 = NewDouble((double)_a_144 * DBL_PTR(_b_145)->dbl); 
        } 
        else { 
            if (IS_ATOM_INT(_b_145)) { 
                _c_146 = NewDouble(DBL_PTR(_a_144)->dbl * (double)_b_145); 
            } 
            else 
            _c_146 = NewDouble(DBL_PTR(_a_144)->dbl * DBL_PTR(_b_145)->dbl); 
        } 
    } 
 
    /** 	return c*/ 
    DeRef(_a_144); 
    DeRef(_b_145); 
    return _c_146; 
    ; 
} 

The easiest thing to do here is probably to write a wrapper function right below the above code:

double MyFunctionDbl( double ad, double bd ){ 
	object a, b, c; 
	double cd; 
	 
	a = NewDouble( ad ); 
	b = NewDouble( bd ); 
	 
	c = _1MyFunction( a, b ); 
	cd = DBL_PTR( c )->dbl; 
	DeRefDS( a ); 
	DeRefDS( b ); 
	DeRefDS( c ); 
	printf("MyFunctionDbl ad %f  bd %f cd %f\n", ad, bd, cd ); 
	return cd; 
} 

And then call that. I wrote this test program to use it:

include std/dll.e 
 
constant 
	VB = open_dll( "/home/matt/eu/test/vb.so" ), 
	MYFUNC = define_c_func( VB, "MyFunctionDbl", {C_DOUBLE, C_DOUBLE}, C_DOUBLE ) 
 
? c_func( MYFUNC, { 0.5, 0.25 }) 
? c_func( MYFUNC, {1, 1 }) 

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu