|
Hi, I want to save data in a .dat file, but when I open the created .dat file, I can read the text in it. How can I make the data unreadable? Thanks everyone. -Bruce
|
|
|
|
|
Hi,
you could create a binary file (use BinaryWriter instead of TextWriter), it would be
faster and more compact, but then you could still recognize (most of) the string data.
and you could use cryptography; .NET has some classes for this.
It all depends on how secure you want your data, and how much effort you want to put in it.
|
|
|
|
|
We are making a project using C#,it is an image processing project, we want to calculate the generalized eigenvectors and eigenvalues for two matrices...
In the DotNetMatrix I found the calculation of eigenvectors and eigenvalues but for one matrix only
Can anybody help?
Thanks,
m w
|
|
|
|
|
Hi,
please read the Christian Graus's articels related to the image processing from this forum ........it is a very usefull and helpful for biggner .........i like these articles.....you can also search the other author's articles.
|
|
|
|
|
Hi,
By your help I able to draw the any shape into the pictureBox and able to save the drawing.
It is a simple way to save any image from the pictureBox
pictureBox2.Image.Save(saveFileDialog1.FileName);
but above command do work when any image is already load onto the pictureBox.otherwise some error occur like that:
"NullReferenceExpection was unhandled !"<br />
"Object reference not set to an instance of an object."
“this is because you can't actually draw inside a picturebox. Although it may look like you're doing so, you are in fact drawing 'on top of' the picturebox and the image is not changed. So, if you haven't loaded an image, then the Image property will still be null.”
“If you use a picturebox, put a picture in it, and draw on it first. Then you can save it. CreateGraphics should be used only for drawing things you want to be able to erase, such as rubber bands. It is not for persistent drawing, and certainly it makes your picture box a waste of time, it never does anything”
Solution of above problem is that
“You need to make the graphics drawn on the PictureBox to be a persistent bitmap then only you can save the image.
Use a bitmap to draw the images upon and then reflect it upon your pictureboc. When you want to save just save the bitmap.”
So, I use follwing command to draw any thing
Bitmap bmp = new Bitmap(pictureBox.Width, pictureBox.Height);<br />
Graphics g1 = Graphics.FromImage(bmp);<br />
Graphics g2 = pictureBox.CreateGraphics();<br />
Pen p = new Pen(Color.Red, 5);<br />
g1.DrawEllipse(p, e.X, e.Y, 50, 70);<br />
g2.DrawEllipse(p, e.X, e.Y, 50, 70);
And use follwing command for save the drawing
if (saveFileDialog1.ShowDialog() == DialogResult.OK)<br />
{<br />
<br />
bmp.Save(saveFileDialog1.FileName);<br />
<br />
}
Am I success???
You notice that I use both bitmap and pictureBox at a time
Bitmap bmp = new Bitmap(pictureBox.Width, pictureBox.Height);<br />
Graphics g1 = Graphics.FromImage(bmp);<br />
Graphics g2 = pictureBox.CreateGraphics();<br />
g1.DrawEllipse(p, e.X, e.Y, 50, 70);<br />
g2.DrawEllipse(p, e.X, e.Y, 50, 70);
I used bitmap for save(hard copy) the drawing and pictureBox used for seeing(soft copy) the image from the screen ………Am I right?
Many Thanks
|
|
|
|
|
Why are you both drawing on the image and on the screen? You are still just drawing on the screen where the picture box happens to be, so the graphics will disappear whenever the window updates.
Why not just how the image in the picture box?
---
single minded; short sighted; long gone;
|
|
|
|
|
if i use only Bitmap like as
Graphics g1 = Graphics.FromImage(bmp);
then drawing do not appear on the screen. i used Bitmap for save the drawing...............So i also used
Graphics g2 = pictureBox.CreateGraphics();
if you have other solution then tell me........
thanks
|
|
|
|
|
The reason it's called a picturebox is that it has a property called Image, which you can pass an Image or Bitmap to, and it will draw it to the screen. You really should buy a book on WinForms and read it.
You need to call Invalidate() on the control to get it to redraw itself when you change the Bitmap, but if you set the Bitmap you're drawing to, to be the Image of the control, it will draw it for you.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
zeeShan anSari wrote: if you have other solution then tell me...
I just did.
---
single minded; short sighted; long gone;
|
|
|
|
|
zeeShan anSari wrote: Graphics g2 = pictureBox.CreateGraphics();
Looks like I answered you before. This is a total waste of time. g1 draws to the Bitmap, and the picturebox displays the bitmap. CreateGraphics is both superfluous in this case, and still as useless as the last time you asked about it.
zeeShan anSari wrote: I used bitmap for save(hard copy) the drawing and pictureBox used for seeing(soft copy) the image from the screen ………Am I right?
You're wasting your time drawing to the picture box, what did you think a picture box is ? It's a control that displays a bitmap 'for seeing'.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi
i want to know how to read,delete,insert,update database(Ms Access)using c#.if anybody know please reply.
|
|
|
|
|
Hello,
The best way to get the desired result fast is to use ADO.NET connections and commands.
Tutorials can be found here: http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx
|
|
|
|
|
Look through these articles C# Databases[^] here on CP. If you get stumped, ask a more general question. Your post is way to broad...
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
If his post was already too broad, asking an even more general question wouldn't help. He should ask a more specific question.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Maybe I should have rephrased general question as specific question
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Hi.
I am trying to write a wrapper for the standard VC1 decoder, and I need to resolve a "TypeLoadException"
The decoder comes an an executable which I've turned into a .dll. This decoder has about a ton of structures, most of the containing other structures, arrays of structures, and unions of structures.
I need help converting the following to managed code:
The unmanaged structure is this:
typedef struct<br />
{<br />
vc1_eBlkType eBlkType; <br />
FLAG Coded; <br />
union<br />
{<br />
vc1_sBlkIntra sIntra; <br />
vc1_sBlkInter sInter; <br />
} u; <br />
} vc1_sBlk;
As you can see it contains an enumerator and a union of another type of struct.
I've taken the unmanaged vc1_sBlkInter structure
typedef struct<br />
{<br />
vc1_NumZeroCoef NZC; <br />
HWD16 DC; <br />
HWD16 ACTop[7]; <br />
HWD16 ACLeft[7]; <br />
HWD16 SmoothRows[16]; <br />
} vc1_sBlkIntra;
And turned it into a managed structure :
[StructLayout(LayoutKind.Sequential)]<br />
public unsafe struct vc1_sBlkIntra<br />
{<br />
ushort NZC; <br />
short DC; <br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)] public short[] ACTop; <br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)] public short[] ACLeft; <br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public short[] moothRows; <br />
};
Now, I am trying to turn vc1_sBlk into a managed structure as well.
The last attempt is this
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]<br />
public unsafe struct vc1_sBlk<br />
{<br />
[FieldOffset(0), MarshalAs(UnmanagedType.I4)]<br />
public vc1_eBlkType eBlkType; <br />
[FieldOffset(4), MarshalAs(UnmanagedType.AsAny)]<br />
public byte Coded; <br />
[FieldOffset(5), MarshalAs(UnmanagedType.Struct, SizeConst = 64)] public vc1_sBlkIntra sIntra; <br />
[FieldOffset(5), MarshalAs(UnmanagedType.Struct, SizeConst = 64)] public vc1_sBlkIntra sInter; <br />
} ;
But I have pretty much tried every kind of marshalling mentioned online, but I keep getting this error:
"Could not load type 'vc1_sBlk'...because it contains an object field at offset 5 that is incorrectly aligned or overlapped by a non-object field."
I am really stuck here and I can't find an answer to this anywhere.
ANY help would be greatly appreciated.
Tom
|
|
|
|
|
AFAIK value types in CLR must be "naturally aligned", meaning their address (and hence
also their offset within a struct or class) must be a multiple of their size.
So you cant put an int at an offset of 5.
But on the other hand structs in C/C++ get padding bytes by default to achieve also
"natural alignment".
(I think there is a switch to turn this off, but one normally does not do that).
You should be able to check this either by printing some actual addresses (in hex!),
or by showing some offsetof() results, in your C/C++ code.
If so, this means sIntra in vc1_sBlk is actually at offset 8.
Lucky for you, now you can have C# and C/C++ agree and work together.
|
|
|
|
|
Hi Luc.
Thanks for the replay, but it brings up some new questions.
First about the offset. The way I figured it was that offset is the number of bytes to offset. So for one int and one short the offset should be 5 bytes.. Am I getting this wrong.
I also tried changing the offset to 8, but now I am getting this error
"Cannot marshal field 'sPosition' of type 'vc1DEC_sState': The type definition of this field has layout information but has an invalid managed/unmanaged type combination or is unmarshalable."
when I am trying to marshal the IntPtr that points to the structure type 'vc1DEC_sState' in the VC1 decoder. This structure hold the structure 'sPosition' which holds another structure, which in turn holds the 'vc1_sBlk' structure in which I changed the offset of 'sIntra'.
So my C# and C have yet to agree, but I will try to somehow get the size of 'vc1_sBlk' and of 'sIntra' from the C code.
If you (or of course anyone else) have more ideas, I really need them.
10x
|
|
|
|
|
TomWolfstein wrote: that offset is the number of bytes to offset
correct
TomWolfstein wrote: So for one int and one short the offset should be 5 bytes
wrong. short is 2B.
Anyway, keep comparing/checking the offsets on both sides until they agree.
And of course, if you dont want to transfer some sub-struct from one side to the other,
just make it an IntPtr.
One more warning: long on CLR means 8B, not 4B (and IntPtr is either 4B or 8B depending
on Win32/Win64).
One more thought: maybe it is wise to fill the alignment gaps with explicit variables,
something like byte myReserved1; byte myReserved2;...
Sorry that's it for now; I am not available tonight...
|
|
|
|
|
Hi.
You are right about the short of course. I meant byte and got confused with the marsahlled arrays.
The problem with IntPtr (and with padding) is that if the managed struct is not defined exactly as the unmanaged struct, it gets garbled when marshaling the IntPtr to struct and I can't get the data I need.
Thankss for your help so far.
If you think of anything else later, I'll be happy to hear (read) it.

|
|
|
|
|
Hi Tom,
1.
please read again my earlier post about the padding bytes, and check it for the C side.
I am rather sure it is true C/C++ inserts them. You should verify to make absolutely sure.
My claim is: a C struct {char; int;} will have a size of 8, and probably
a C struct {int; char;} will too. Please check both.
2.
where you write
[FieldOffset(5), MarshalAs(UnmanagedType.Struct, SizeConst=64)]
I would replace 5 by 8 as explained before,
and I would drop the SizeConst=64 since that applies only to arrays and strings, not structs
(so I guess you could drop the MarshalAs(UnmanagedType.Struct too since that does not
add any information)
3.
my remark about IntPtr was not to the point; it applies to classes (in case you dont need
them), it does not apply to structs. For structs whose value you dont need you can omit them,
as long as you keep the FieldOffset values correct.
(Temporarily) omitting some substructs may help you in verifying that the Marshaling of
the remainder succeeds (before you got all the details right in those omitted substructs).
4.
You can always instantiate a struct and get its Marshal.Sizeof() which means the number
of bytes that will cross the border given the current information (as in FieldOffset
and MarshalAs attributes). This sizeof should match the C-side sizeof() value.
So I suggest you add logging to both sides to actually see them.
|
|
|
|
|
Hi.
I tried what you suggested and came up with the conclusion that there is no extra padding for structs.
The 64 bytes I calculated is the same size i got from Marshal.SizeOf and from the C code.
What I also found out is that you cannot use LayoutKind.Explicit and FieldOffset in a struct that has both values and refrences (or with refrences at all).
Check out Mattias Sjögren reply here:
http://www.dotnet247.com/247reference/msgs/5/27796.aspx[^]
So I worked around (I hope) the union problem by creating a struct that contains those two fields, and now it looks like this:
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public unsafe struct vc1_sBlk<br />
{<br />
public vc1_eBlkType eBlkType; <br />
public byte Coded; <br />
public union u;
};<br />
<br />
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public unsafe struct union<br />
{<br />
<br />
public vc1_sBlkIntra sIntra; <br />
public vc1_sBlkIntra sInter; <br />
};
So now these structs are completely managed and there is no need for the explicit layout anymore. Hwever, this didn't dolve the problem, which leads me to belive that I have asked the wrong question.
The original problem came up when I tried to do this:
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public vc1_sBlk[] sBlk;
And no matter what I tried to marshal 'vc1_sBlk' or 'vc1_sBlkIntra', I kept getting the exception. So i tried removing the structures (which are refrences AFAIK) from 'vc1_sBlk' and it worked. Then I returned the structures, but changed the decleration to
public vc1_sBlk sBlk;
and it also worked. Everything is accessible and works fine.
So the question is can I declare a marshalled array that has refrences in it, and if not (which I assume is the case), how can I work around it?
Tom
(Sorry I am pouring all this data on you. I am just trying to be detailed to help you help me, and anyone else who should encounter this problem).
|
|
|
|
|
Hi Tom,
I am afraid you've lost me somehow.
1.
For unions the only way out I know in C# is by using FieldOffset.
Your "struct union" is not a union at all, it is a struct with two (sequential) members.
Of course, if the members are small, and the other side is flexible (i.e. no set of registers
cast in hardware, and no software in OBJ/EXE-only form, and no implicit conversion, see below)
then you could change it in this way, but it is a change, it is no longer what was intended
originally.
If you rely on union members to occupy the same memory (e.g. when you write to one member
then read the other to obtain a bit-wise translation, such as 4 bytes to 1 int), then you
need real unions of course.
2.
TomWolfstein wrote: The 64 bytes I calculated is the same size i got ...
I dont know which struct you refer to. If it is struct vc1_sBlkIntra, then we agree that
the size is 64B; and there is no need for padding, every member is short/ushort so they
all automatically align. If however it is vc1_sBlk from your original post
typedef struct
{
vc1_eBlkType eBlkType; /** Block type */
FLAG Coded; /** Non zero AC coefficients for Intra,
non zero AC/DC for Inter */
union
{
vc1_sBlkIntra sIntra; /** Intra block state information */
vc1_sBlkInter sInter; /** Inter block state information */
} u; /** Intra/Inter union */
} vc1_sBlk;
then depending on the size of vc1_eBlkType (lets say multiple of 4B) and FLAG (1B?)
I expect padding bytes to get the union aligned to a 4B multiple on the C/C++ side,
and also on the C# side (assuming Sequential, otherwise everything may get reordered).
3.
structs are value types, not references.
arrays are references, unless they are in a struct and carry marshaling info to tell
otherwise (ByValArray and SizeConst).
Marshaling references is complex, each pointer points to some memory block that
sooner or later may have to be a managed object. When given the choice, I tend to keep
things as simple as possible in marshaling, e.g. by putting everything as values in
one (big) struct, and by passing reference types one by one, using function calls
instead of struct members; and by avoiding structs/classes that contain references
all together (if needed, one can pass a null reference, then call a function to
accept a reference type and adapt the reference).
4.
I am getting confused about your structs; there are an unknown number of them, and they
have difficult names. So if you want detailed help, please be as specific and complete
as you can (and show both C and C# side as you did in your original post).
5.
it has been my experience one must build up the p/invoke and marshaling knowledge
by starting of with simple cases, observe them in detail, and get them to work
(compile, run without exception, pass the right data, checked by logging and/or
returning as a function result what was passed in).
And then gradually try more complex things. It is in general a bad idea to throw in all
the structs and classes at once, and have limited observability: it keeps you guessing
and probably wasting lots of time.
I tend to include logging code that dumps all the values that cross the borders,
I switch it on or off with one flag, and I leave the code in after I got it working,
so as soon as a functional change is required, it is there to help...
Hope this helps.
|
|
|
|
|
Hi.
Sorry it took me so long to answer. It's exam period..
I'll start with the end. I completley agree that it's best to learn P/Invoke and the principles of marshaling unmanaged code to managed code, and that simple examples should come before diving into a project like this.
I wish I knew all this 3 month ago when I started this. I didn't, and didn't have much choice as I am not writing this for my pleasure but as a final project for my degree. I am as unhappy with this as much as you can imagine. I want to thank you again for taking the time to explain all of this to a newbie like me.
Besides, don't they always say the best way to learn to swim is to just dive in
Now back to the fun (?).
1. I understand the structure I created to replace the union is not a good idea. I tried it as a way of getting the structure containing to occupy the same size it would have, had I used a union.
Now that I think the problem is somewhere else I can probably (hopefuly) change it back.
2. You are probably right here again. When I tried to offset the union 8 bytes, the alignment error disappeared and was replaced by the error caused by trying to marshal an array of structs.
Maybe this is because some of these structs have marshaled arrays in them.
4. Trust me, you are not the only obe confused by these structs, but as I said at the begining, the C source code is not mine. It is an open source implementation of the VC1 video standart. I'll be happy to send it to you if you are interested.
Meanwhile, I'll try to be clearer. I imported all of structs from the C code to C#, and marshalled all of them.
Basicaly there are two structures who contain in them, by way of value, reference and other, all of the other structures in the code.
I am sending an IntPtr from the C# code to the VC1 decoder (C code), and return that IntPtr with the address of the structure I want to access (I do it with 'out' rather than actually returning it, but the result is the same).
Right now some of the fields in the super struct (int C#) are garbage, and some are perfectly accessible. I think (and please correct me if I am wrong. there is a good chance I am), that this is because I did not import and marshall ALL of the structs, and this is causing an alignment error in the C# super struct, making it not the same size as the C code struct.
I have this struct 'vc1_sMB':
<br />
[StructLayout(LayoutKind.Sequential)]<br />
<br />
public unsafe struct vc1_sMB<br />
{<br />
vc1_eMBType eMBType; <br />
vc1_eACPred eACPred; <br />
vc1_eBlkType eBlkType; <br />
byte OverlapFilter; <br />
byte Skipped; <br />
byte CBPCY; <br />
byte MVBP; <br />
vc1_sQuant sQuant; <br />
<br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public vc1_sBlk[] sBlk; <br />
<br />
<br />
};
As you can see in the last line, there is a marshaled array of 'vc1_sBlk' structs.
The C version of this struct is exactly the same apart ftom the marshaled array, and I left the arrays original definition commented.
'vc1_sBlk' looks like this (now marshaled like you said to implement the union):
<br />
[StructLayout(LayoutKind.Explicit, CharSet=CharSet.Ansi)]<br />
public unsafe struct vc1_sBlk<br />
{<br />
[FieldOffset(0), MarshalAs(UnmanagedType.I4)] public vc1_eBlkType eBlkType;<br />
<br />
<br />
[FieldOffset(4), MarshalAs(UnmanagedType.U1)] public byte Coded; <br />
<br />
<br />
[FieldOffset(8)] public vc1_sBlkIntra sIntra; <br />
[FieldOffset(8)] public vc1_sBlkIntra sInter; <br />
};
While it's original definition in the C code is this (FLAG is a 1B short):
typedef struct<br />
{<br />
vc1_eBlkType eBlkType; <br />
FLAG Coded; <br />
union<br />
{<br />
vc1_sBlkIntra sIntra; <br />
vc1_sBlkInter sInter; <br />
} u; <br />
} vc1_sBlk;
And as you've seen before 'vc1_sBlkIntra' looks like this in c#(the C code is in comments):
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public unsafe struct vc1_sBlkIntra<br />
{<br />
ushort NZC; <br />
<br />
short DC; <br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)] public short[] ACTop; <br />
<br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)] public short[] ACLeft; <br />
<br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public short[] moothRows;<br />
<br />
};
And 'vc1_sBlkInter' looks like this:
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public unsafe struct vc1_sBlkInter<br />
{<br />
<br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public ushort[] NZC; <br />
<br />
<br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public vc1_sMotion[] sMotion;<br />
<br />
} ;
I will not bother you with all the definitions of the other structures (everything that starts with an s, since there is nothing interesting there but normal type variables).
So 'vc1_sBlk' has in it structures that contain marshaled arrays (which like you said are references, if it matters).
All of this compiles without problem, but after I changed the offset to what you suggested, the error I got is this:
Cannot marshal field 'sPosition' of type 'vc1DEC_sState': The type definition of this field has layout information but has an invalid managed/unmanaged type combination or is unmarshalable.
(I apologize. This really is never ending)
'vc1DEC_sState' is this (only the first line is important, but I pasted all of it):
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public unsafe struct vc1DEC_sState<br />
{<br />
public vc1_sPosition sPosition; <br />
vc1_sPicture pPicture; <br />
<br />
public int FrameNum; <br />
<br />
<br />
vc1_sMB pMB; <br />
<br />
<br />
<br />
int NumFields; <br />
int MaxMBs; <br />
vc1_sLevelLimit pLevelLimit; <br />
<br />
<br />
vc1_sSequenceLayer sSeqParams; <br />
vc1DEC_sPictureLayerParams sPicParams; <br />
<br />
byte NotFirstMode3InFrame; <br />
<br />
byte LevelCodeSize; <br />
byte RunCodeSize; <br />
<br />
byte ZigZagTableIndex; <br />
byte FirstFrameInStream; <br />
byte BitplaneCodingUsed; <br />
<br />
byte FirstCodedBlock; <br />
<br />
public vc1_sReferencePicture pCurrentRef; <br />
<br />
<br />
vc1_sMotionHist pMVHistBuffer; <br />
uint FieldCount; <br />
<br />
}
And inside it, the 'sPosition' mentioned is this (again just notice that vc1_sMB is defined here):
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public unsafe struct vc1_sPosition<br />
{<br />
vc1_ePictureType ePictureType; <br />
vc1_ePictureFormat ePictureFormat; <br />
vc1_eProfile eProfile; <br />
vc1_eMVMode eMVMode; <br />
vc1_eMVRange eMVRange; <br />
byte BottomField; <br />
byte SecondField; <br />
vc1_sMB pCurMB; <br />
vc1_sMB pStartMB; <br />
vc1_sMotionHist pMVHist; <br />
uint SizeMB; <br />
ushort X; <br />
ushort Y; <br />
ushort SliceY; <br />
ushort WidthMB; <br />
ushort HeightMB; <br />
public uint CodedWidth; <br />
public uint CodedHeight; <br />
uint MaxCodedWidth; <br />
uint MaxCodedHeight; <br />
byte PQuant; <br />
byte BFraction; <br />
byte NumRef; <br />
byte RefField; <br />
byte IntraBias; <br />
byte RangeYScale; <br />
byte RangeUVScale; <br />
byte FastUVMC; <br />
vc1_ePictureRes ePictureRes; <br />
vc1_sReferencePicture pReferenceOld; <br />
vc1_sReferencePicture pReferenceNew; <br />
vc1_sReferencePicture pReferenceB; <br />
vc1_sReferencePicture pReferenceNoIC; <br />
<br />
<br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]<br />
public vc1_sScaleMV[] pScaleMV; <br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6*64)] public short[] pSmooth;<br />
} ;
All of this brings us back to the begining (did I apologize already for the length of this?)
If you remember in the begining of this post, 1e100000000000 lines above, I said that the last line of 'vc1_sMB' is the declaration of a marshaled array of 'vc1_sBlk'.
If instead of this array I declare this:
public vc1_sBlk sBlk; /** Block level information */ Then there is no error.
I can't get access to all of the fields in all of the structs, but at least there is no error.
So, finally, I suspect this array.
Am I right to suspect it?
Am I on the right way to gain normal access to the structs fields?
Would it help if I sent you the C code?
I did not intend for this to be the longest post ever. I am deeply thankful for the time you are putting into just reading all of this, not to mention trying to understand and come up with solutions.
Thanks.
Tom.
|
|
|
|
|
Hi Tom,
1.
yes I would like to have the C code in a compilable and runnable form. Please email it
using the email button below. Have some questions:
1.1. Which tool do you use to build it ? (I hope Visual Studio 6)
1.2. Does it use "normal" sizes (1B byte, 2B short, 3B int, ...) ?
1.3. Where did you get the source exactly ?
1.4. Did you change anything ? If so did you comment that in the source ?
1.5. Did you add code to print out:
- struct sizes ?
- and field offsets ? Are they what you expected ?
- field values ?
2.
I entered your C# code in a C# project, but I am missing a lot:
several vcl_### types such as vc1_eMBType; I hope most of them are int enums.
I think you best also send me the source of C# class that is supposed to call the C stuff.
3.
to access vc1DEC_sState.sPosition one must get all its members marshalled (almost) correctly;
as long as something is wrong in say vc1_sPicture, it will continue to give that kind
of run-time errors.
And that's exactly why I tend to build a marshalling job from bottom to top,
so you get something working and this gives you the energy to continue...
4.
Are you sure you need the unsafe keyword ? what is it supposed to bring you ?
5.
some of your fields are public, most of them not. Why is this ?
If you dont need to access most of the fields in C#, you can replace them by something simpler
having the same size (such as vc1_sMB in vc1DEC_sState !?!?
Greetings
|
|
|
|
|