|
It's easier to use pinvoke to call functions from c++ dlls.
There is a C++/CLI forum, if you ask there, Nish is bound to find it and help you.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi,
thank you for your reply!
Finally I found the problem by my own.
The problem was the structure:
<br />
struct TMP<br />
{<br />
DWORD x;<br />
WORD z;<br />
};<br />
A sizeof(TMP) told me that it's 8 Bytes big.
The strange thing here is that a DWORD is 4 Bytes and a WORD is 2 Bytes big (confirmed by sizeof(DWORD) and sizeof(WORD). If you count it together it's 6 and not 8???
The DLL function expected an array of 6 Bytes structs.
What it got was an array of 8 Bytes structs, which led to that the Dll got garbage while it was reading the second array element.
What I did now, was splitting up the DWORD into two WORD variables:
<br />
struct TMP2<br />
{<br />
WORD x1;<br />
WORD x2;<br />
WORD z;<br />
};<br />
sizeof(TMP2) says that it's 6 Bytes big now. Really strange.
|
|
|
|
|
There is nothing really strange about that, C (and C++ I guess) pads all its structs
so all elements are "naturally aligned" (to an adr that is a multiple of their size),
and aligns the entire struct to the size of the largest element, in your case 4B due to the DWORD/int.
The reason is the compiler can then emit code that manipulates 4B quantities without worrying
about alignment and/or achieving highest performance. (Some processors do not know how to
load a DWORD from an unaligned adr, others do but take more time to do it).
The net result is:
1)
if your struct's size is not a multiple of 4 but contains elements sized 4B, the struct will
act as if its size is a multiple of 4B (even when sizeof shows otherwise).
2)
if the elements in your struct are not "naturally aligned", the struct will be padded with
extra bytes to achieve the natural alignment (=each element gets aligned according to its size).
So
struct {
byte a; // offset 0
short b; // 1 ? not naturally aligned
byte c; // 3 ? OK
byte d; // 4 ? OK
long e; // 5 ? not naturally aligned
}
gets compiled as if it were:
struct {
byte a; // offset 0
byte bDummy;
short b; // offset 2
byte c; // offset 4
byte d; // offset 5
byte eDummy1;
byte eDummy2;
long e; // offset 8
}
The function you used was an old one, relying on a stride of 6B, so something special needed
to be done. In C (and C++ I guess) there are compiler switches and/or pragmas to disable
the alignment/padding. In C# your splitting the 4B into two 2B elements is probably the
best way to get what you needed.
Luc Pattyn
|
|
|
|
|
Hi ~
For the databinding for the control class
i.e. Control.DataBindings.Add(string propertyName,object dataSource,string dataMember)
for the parameter of dataSource and dataMember, how can i bind the value of the control to the specific in array
e.g. if i have a class
public class Person{
public object[] extras
}
then i want to bind the control with the second element in Person.extras i.e. Person.extras[1]
i try the following ways, but not success
controlObj.DataBindings.Add("Text, person.extras, new object[] {1});
and
controlObj.DataBindings.Add("Text", person, "extras[1]");
Thank
|
|
|
|
|
The Control i need to being binding to is allow to bind the single value only, such as TextBox, can just bind to a sigle value. But ListBox can bind to a list or array because it allow multiple to display in the control
|
|
|
|
|
Hi All,
My task is should create Sharing a folder using web application in .net.
The Sharing folder (and its files) shold be visible to all in network.
I have searched a lot,to get an article,but failed to succeed.
Plz suggest me or else provide a good article as iam new to creating web applications in .net
Thx in advance
Nagaraju
|
|
|
|
|
I heard a collegue of mine mention this, but uncertain of its truth...
software built with Microsoft's .Net (and later) compilers <br />
creates executables in a "common format" that can be run through<br />
commercially-available disassemblers to fully recover the original<br />
source code. the protection against this is to use scramblers.
Can anyone veryify this?
Thanks,
Johnny
|
|
|
|
|
Simplistically, code written against .NET is compiled into IL (intermediate language). This IL can be reversed back into source code. Obfuscators can be used to make this reversing much more complicated.
Now, it is important to note that no source code (in any language) is 100% safe from reverse-engineering. Given the time/motivation you can reverse any source.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Follow up question: is it (now) easier to reverse engineer code compiled in .NET?
|
|
|
|
|
From unprotected code, yes.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks all! I can sleep better tonight
|
|
|
|
|
It's close to the truth, but it's not truth.
software built with Microsoft's .Net (and later) compilers
creates executables in a "common format" that can be run through
commercially-available disassemblers to fully recover the original
source code.
False.
The original source code can not be recovered as it's not included in the compiled code.
Reverse engineering can recreate code that will do the same thing as the original code and will compile into an identical executable, but the recreated code will not be the same as the original source code.
the protection against this is to use scramblers.
False.
Scramblers provide some level of protection, but it's impossible to completely protect any code from reverse engineering.
---
Year happy = new Year(2007);
|
|
|
|
|
Hi every body,
Can I customize the paper size and print a crystal report directly by coding. And my client have some printed papers, he needs to print the data at required places only. Like "Name : Code Project" here Name : is laready printed and it has to print CodeProject at specified place exactly.
How can we do it please advice me.Thank you.
Regards,
S/W Engineer
Akebono Soft Technologies
aleem_abdul@akebonosoft.com.
|
|
|
|
|
I created a C# appln using .Net 1.1v framework, which is tested on a system having .Net 2.0v framework installed. Application is opening and working fine. But some places, application is throwing messages "Object reference not set to an instance of an object." and continues to work. But these messages no where appeared on my system which is having only .Net 1.1 framework. But when I install .Net 1.1v framework on the test machine, application is taking the 1.1 framework and working fine for the previous test case. Why some classes of .Net 2.0 are not working with 1.1v framework created application assembly. Is .Net2.0 is backward compatible with .Net1.1???
Thanks in advance...
Regards,
Sunil Jampa.
|
|
|
|
|
Sunil Jampa wrote: Is .Net2.0 is backward compatible with .Net1.1???
I guess you've found that the answer is 'no'. In fact, you can mark your app to require the exact version that was used to build it. I'd have said that overall I'd not expect a problem, you should try to work out the issue, just in case it needs resolving either way.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
This In General, we do like this only. We will work and create appln on .Net1.1, and later point of time, users can install .Net2.0 or .Net3.0 or some future release...We cannot pinpoint each piece of code again and again and do some work around for each framework. .Net framework itself should take care about this issue. But it is not doing.
Any body can please comment on this statement ".Net 2.0 is not backward compatible with .Net 1.1".
Regards,
Sunil Jampa.
|
|
|
|
|
Well, you can either track down the issue and understand it, or you can trawl online forums, hoping someone will make a statement that makes you feel better about the issue you are having. I've never had issues moving from 1.1 to 2.0, and I've moved at least one large project over.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
And one more thing I observed is, Encoding class(ASCIIEncoding.ASCII.GetBytes(msg) method) is giving wrong results. When I try to create a key using the appln which uses .Net2.0 and again I try to create a key with .Net1.1, both keys are different. Here no error message is coming, but the keys are not matching.
This makes me to feel that .Net2.0 is not backward compatible with .Net1.1.
Please if anybody facing the same problem can throw some light on this...
Thanks in advance...
Regards,
Sunil Jampa.
|
|
|
|
|
|
The only reason why backward compatibility should exist is because you want to use .NET2.0 features or improvements. In that case, you will have to correct for incompatibility. You cannot prevent Microsoft to correct bugs and potentially unsafe code.
Microsoft designed the .NET framework to avoid problems with compatibility as good as possible. You can specify wich dll versions must be used in an appplication. I recommend to read Jeff Richters book Applied programming .NET framework (o something like that). In this book you find four chapters on deployment, assemblies and versoning. This exactly addresses your topic (which is very complex).
Regards,
Rudolf Heijink
|
|
|
|
|
Hi,
Sunil Jampa wrote: Is .Net2.0 is backward compatible with .Net1.1???
It cannot be 100% unless either no existing class is modified or each framework version also contains all prior versions. Both are not really an option.
I don't remember exactly where this happened but I had a case where .Net 1.1 had a small bug and I had to built a workaround in my code to get around it. After moving to .Net 2.0 I realized that this bug has been resolved (which is a good thing) but as a result my workaround (logically) began throwing errors.
Robert
|
|
|
|
|
No, it is not backwards compatible, and Microsoft has never ever claimed it to be.
As already mentioned, you can find the breaking changes on MSDN[^]
Sure backwards compatibility is a great thing in theory - in practice we call it "DLL Hell" and it is a blessing Microsoft didn't make that mistake with the .NET Framework. As far as I remember you can set your application to not even attempt to run on the 2.0 Framework (I do wish this would have been the default setting, but we can't have it all).
|
|
|
|
|
All that is required is a single line in the application's configuration file (applicationname.exe.config):
[startup]
[supportedRuntime version="v1.1.4322"/]
[/startup]
Ok, 3 lines (replace square brakets with angle brakets)
|
|
|
|
|
Hello ppl,
Long time since I posted anything here...
Well, I've written a small app that reads a file from the disk into objects and stores them in a list. Then, what I wanted was to edit each of these objects individually and save them back to the disk. Yeah, just a stupid editor.
So, I discover a nice thing about DataGridView: I can use it together with BindingSource to access items in a List<>. Since I already have the list, I just do that:
<br />
_list = new Records("C:\\somefile.list");<br />
BindingSource bs = new BindingSource(_list, "");<br />
<br />
this.dgEntries.DataSource = bs;
Records is a class that implements the IList interface. So far, so good.
Thing is, I go ahead and delete a few rows from the list and expect to see the result. But unfortunatly, the BindingSource seems unable to propagate the change correcly. No change inflicted upon the DataGridView is propagated to the list. Actually, I can't even sort the list.
Does anyone has a insight over the subject? Anything that would shed a light on how to correctly use the BindingSource would help me a lot.
By the by, I'm using .Net Framework 2.0 and C#.
|
|
|
|
|
Hi,
have a look at one of my articles[^]. It adresses the issue with the missing sorting and filtering capabilities. For this I implemented a new class named BindingListView (which is contained in the project). It needs a type and an IList to work and can be bound to the DataSource property of the DataGridView. I haven't actually tested if change operations work but you might have a good chance that it does because I've implemented the complete IBindingListView interface which is the interface the DataGridView internally works one no matter what you bind to its DataSource property.
Be sure to download the DataGridView version and not the DataGrid version and please give me some feedback it it works or not .
Robert
|
|
|
|