473,503 Members | 1,681 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(JSContext *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(IntPtr cx, IntPtr message, JS.JSErrorReport
report);
<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><* >
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct JSErrorReport
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string filename;
public UInt16 lineno;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string linebuf;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string tokenptr;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string uclinebuf;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string uctokenptr;
public UInt16 flags;
public UInt16 errorNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string ucmessage;
[MarshalAs(UnmanagedType.ByValTStr, 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 3712
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(UnmanagedType.ByValTStr, 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.com
"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(JSContext *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(IntPtr cx, IntPtr message,
JS.JSErrorReport report);
<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><* >
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct JSErrorReport
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string filename;
public UInt16 lineno;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string linebuf;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string tokenptr;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string uclinebuf;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string uctokenptr;
public UInt16 flags;
public UInt16 errorNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string ucmessage;
[MarshalAs(UnmanagedType.ByValTStr, 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
2213
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:...
1
1664
by: Chingon | last post by:
Hello, Does anyone know of a port of the SpiderMonkey JavaScript engine to QNX 4? Thanks, Mike
3
2853
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...
3
4853
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 ...
1
2553
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...
4
3579
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...
6
2625
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...
2
1809
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...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7278
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,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
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...
0
7458
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...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
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...
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.