Can't add a reference to specified file

B

Bura Tino

Hi,

About a year ago I wrote C++ excel add-in, which provides a few worksheet
function which I still use quite frequently and successfully. Now I want to
use the same function in VBA. From what I understand, I need to add a
reference to the add-in first, but when I pick my xll from the browse menu,
I get the "Can't add a reference to specified file" error. Something is
probably screwed inside my xll. Can you recommend what I should look at.

Many thanks!

Bura.

PS: The function that I want to use is one that takes a URL and returns the
contents of that resource. In particular, I'm running a few servers and I
need for my VBA code to find the live ones. So I request an
http://serverN/AreYouAlive.jsp, and the server replies "yes" and my function
passes it through, or the request time outs and my function returns "no". In
VBA I would like to be able to say if getURL(http://serverN/AreYouAlive.jsp)
= "yes"... Perhaps someone could suggest an alternative way of doing this
and then the primary question is this post will become moot. Thanks again.
 
B

Bura Tino

Tom Ogilvy said:
If it is a xll/dll, I believe you would declare it just like a windows API.
(rather than set a reference to it).

This article gives an example of making a DLL and calling it from VB (should
be the same for VBA).

http://support.microsoft.com/default.aspx?scid=kb;en-us;153546&Product=vbb

Include the path if it isn't in the system directory I believe.
HOWTO: Pass Optional Parameters to a C DLL Function from VB

--

Thanks Tom. Couldn't quite get it to work. So I'll post more info and
perhaps you or someone else could suggest the precise declaration to use.

1. Function Registering Table:
static LPSTR func[][14] = {
{ " getURL" , " RP" , " getURL" , " URL String" , " 1", " Transcend", " ", "
", " Non Volatile NOW()" , " This dummy dependency argument is unused inside
the funtion", " ", " ", " ", " "},
};

2. The DEF file snippet:
getURL


3. And here's the very ugly getURL function (but it works)

LPXLOPER __stdcall getURL(LPXLOPER inX) {
static XLOPER xRes;
Excel4(xlfNow, &xRes, 0); // Returns an xltypeNum;
xRes.xltype = xltypeStr;
xRes.val.str = (PUCHAR) " Input not a URL";
if (inX->xltype == xltypeStr) {
string *a = new string(" " + utilityURLToString(toStr(inX->val.str))); //
a function that uses the curl package compiled into the addin.
xRes.val.str = (PUCHAR) a->c_str();
xRes.val.str[0] = a->length() - 1;
xRes.xltype = xltypeStr;
}
return &xRes;
}


This works beautifully in worksheets and I want to have the function getURL
available in VBA!


Very many thanks!!! I would be exstatic if I can get this to work and I
think this will be useful to others as well!

(Hopeful) Bura
 
Top