473,568 Members | 3,014 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DllImport and Structures - spidermonkey

Hello all

Having trouble with getting Error Information from spidermonkey. How would
one convert a C structure to CSharp?

struct JSErrorReport {
const char *filename; // source file name, URL, etc., or null
uintN lineno; // source line number
const char *linebuf; // offending source line without
final \n
const char *tokenptr; // pointer to error token in linebuf
const jschar *uclinebuf; // unicode (original) line buffer
const jschar *uctokenptr; // unicode (original) token pointer
uintN flags; // error/warning, etc.
uintN errorNumber; // the error number, e.g. see
js.msg
const jschar *ucmessage; // the (default) error message
const jschar **messageArgs; // arguments for the error message
}

as well as a C type callback function:
ErrorReporter(J SContext *cx, const char *message, JSErrorReport *report)

I've been working on this thing for a week and only got to the point where I
can get it to call ErrorReporter, but it returns gibberish. - Sample below.
<*><*><*><*><*> <*><*><*><*><*> <*><*><*><*><*> <*><*>
public delegate void CallBackPtr(Int Ptr cx, IntPtr message, JS.JSErrorRepor t
report);
<*><*><*><*><*> <*><*><*><*><*> <*><*><*><*><*> <*><*>
[StructLayout(La youtKind.Sequen tial, Pack = 4)]
public struct JSErrorReport
{
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string filename;
public UInt16 lineno;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string linebuf;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string tokenptr;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string uclinebuf;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string uctokenptr;
public UInt16 flags;
public UInt16 errorNumber;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string ucmessage;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string messageArgs;
};
<*><*><*><*><*> <*><*><*><*><*> <*><*><*><*><*> <*><*>
Any type of help or direction on this thing will finally let me sleep at
night.

Thanks
Thomas

Jan 28 '08 #1
1 3717
Thomas,

Well, you aren't including all of the information that is needed. For
example, what is a JSContext, jschar, uintN?

Regardless, the one thing I can tell automatically that you are doing
wrong is that you are declaring your string types with this attribute:

[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]

The thing is, your structure declaration has pointers to those strings,
they aren't embedded in the structure. You need to declare these as IntPtrs
and marshal the strings yourself, or (and I am not positive that this will
work) change it to a string (without the ByValTStr modifier), both of which
should marshal it as a pointer, which is what your structure declares.

The same goes for the jschar types, if they are just typedefs for
characters.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Thomas" <tc*****@yahoo. comwrote in message
news:db******** *************** ***@ALLTEL.NET. ..
Hello all

Having trouble with getting Error Information from spidermonkey. How would
one convert a C structure to CSharp?

struct JSErrorReport {
const char *filename; // source file name, URL, etc., or
null
uintN lineno; // source line number
const char *linebuf; // offending source line without
final \n
const char *tokenptr; // pointer to error token in linebuf
const jschar *uclinebuf; // unicode (original) line buffer
const jschar *uctokenptr; // unicode (original) token pointer
uintN flags; // error/warning, etc.
uintN errorNumber; // the error number, e.g. see
js.msg
const jschar *ucmessage; // the (default) error message
const jschar **messageArgs; // arguments for the error message
}

as well as a C type callback function:
ErrorReporter(J SContext *cx, const char *message, JSErrorReport *report)

I've been working on this thing for a week and only got to the point where
I can get it to call ErrorReporter, but it returns gibberish. - Sample
below.
<*><*><*><*><*> <*><*><*><*><*> <*><*><*><*><*> <*><*>
public delegate void CallBackPtr(Int Ptr cx, IntPtr message,
JS.JSErrorRepor t report);
<*><*><*><*><*> <*><*><*><*><*> <*><*><*><*><*> <*><*>
[StructLayout(La youtKind.Sequen tial, Pack = 4)]
public struct JSErrorReport
{
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string filename;
public UInt16 lineno;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string linebuf;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string tokenptr;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string uclinebuf;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string uctokenptr;
public UInt16 flags;
public UInt16 errorNumber;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string ucmessage;
[MarshalAs(Unman agedType.ByValT Str, SizeConst = 260)]
public string messageArgs;
};
<*><*><*><*><*> <*><*><*><*><*> <*><*><*><*><*> <*><*>
Any type of help or direction on this thing will finally let me sleep at
night.

Thanks
Thomas

Jan 28 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2221
by: wyl_lyf | last post by:
Hello! I know that spidermonkey can compile and detect if the javascript has any syntax errors. But I'm not sure if it can handle javascript to be ran on the server-side? example: ..response.write("<html>"...) any ideas? thanks!
1
1671
by: Chingon | last post by:
Hello, Does anyone know of a port of the SpiderMonkey JavaScript engine to QNX 4? Thanks, Mike
3
2863
by: Isaac Gouy | last post by:
1) Running a standalone script with SpiderMonkey on Linux js -f scriptfile.js scriptarg How can I get the value of scriptarg from within the JavaScript scriptfile? 2) Running a standalone script with SpiderMonkey on Linux How can I do formated printing to stdout?
3
4858
by: Blake McBride | last post by:
Greetings, I am embedding Spidermonkey in a C app. and I'm having trouble setting class (not instance) property values. For example, I am setting up the class as follows: static JSBool constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
1
2558
by: Stephen Richardson | last post by:
I have a C++ dll which returns a structure, the structure contains a char variable, as shown below. struct MyCStruct { short iNumber; char Name; }; I've declared a structure in C# as shown below
4
3582
by: McKool | last post by:
Hello everybody. I have a problem importing a function from a Dll. This dll was made in C++. I get in troubles when I try to use the following function: Function DLL DWORD __stdcall ReadWithArray( byte MyByte, TStruct* pStruct, long nMaxStructCount, long* pStructReadCount); C# public static extern uint...
6
2631
by: Chad Crabtree | last post by:
As I'm sure some of you already know there is quite a bit of stir on Reddit about a few Javascript Rails clones. Both of them run on Rhino, which brings me to my question. Why is it that both Trimpath and the google guy choose to run on rhino vs Spidermonky. I'm coming here as it's the only place I can think of to find a cogent answer. ...
2
1813
by: zowtar | last post by:
Guys, I am using slackware... js-spidermonkey 1.5 compiled - OK, Pyrex installed, but python-spidermonkey don't build... Screenshot: http://img406.imageshack.us/img406/562/testebp5.png what is the problem? zowtar
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.