I need to create dll using C. But I saw some problems. OK, first: I need function in dll library to compute angle of the line - tgA = dy/dx. Angle = arctg(dy/dx). And I define this in file framework.c:
JSBool computeAngle(JSContext *cx,
JSObject *obj,
unsigned int argc,
jsval *argv,
jsval *rval ) {
double dx, dy, angle;
if (argc != 2) {
return JS_FALSE;
}
if (JS_ValueToDouble(cx, argv[0], &dy) == JS_FALSE ||
JS_ValueToDouble(cx, argv[1], &dx) == JS_FALSE) {
return JS_FALSE;
}
if( dx == 0 开发者_如何学Go) {
if( dy < 0 ) angle = -90;
else if( dy > 0 ) angle = 90;
else angle = 0;
}else angle = atan(dy/dx)*180/M_PI;
return JS_DoubleToValue(cx, angle, rval);
}
But this method doesn't work! I thought that something wrong, and downloaded Sample.zip from Adobe site. I chanded function computeSum on my function, but it still not work. I think that something wrong with JS_ValueToDouble() and JS_DoubleToValue methods. How do you think?
Which part of this method doesn't work? Calling the method inside the dll from another set of code (eg. you've compiled your DLL and created a test program, but it throws linker errors), or you can't compile your dll? If it's the first, your method needs something like the following macro defined:
#ifdef EXPORT
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
In your header (or if the function is not declared in a header, in the C file), you'll require
DLL_EXPORT JSBool computeAngle(JSContext *cx,
JSObject *obj,
unsigned int argc,
jsval *argv,
jsval *rval )
If the error lies when trying to compile your dll, there's a high chance you're not linking to the dll properly - you need to set Project Linker properties (if using MSVS) or use the -l option if using MinGW.
精彩评论