|
MarshalDirectiveException was unhandled<br />
<br />
Cannot marshal 'return value' Invalid managed/unmanaged type combination.
|
|
|
|
|
Your unmanaged code returns a pointer to an array, but your managed code has not been told how to marshall the data. I'm not an expert in this interface but you need to add some more attributes to tell the marshalling code that a pointer is being passed back. You can find more information here[^].
The best things in life are not things.
|
|
|
|
|
If Richard is correct and it's returning a pointer then you may need to copy the data at the pointer to a managed byte array.
byte[] data = new byte[256];
IntPtr result = DLL.Receive(Adr, Len);
Marshal.Copy(result, data, 0, 256);
[DllImport("mrdsio.dll", EntryPoint="Receive", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern IntPtr Receive(int Adr,int Len);
|
|
|
|
|
Dave,
your version offers up a different error,
'AcessViolationException was unhandled'
Attempted to read or write protected memory.
|
|
|
|
|
OK, I'm a little confused as I'm not familiar with Delphi.
Does the function return a single byte, a pointer or a byte array? That it loops 256 times indicates it may be just a byte that is returned which needs to be added to a separate byte array?
|
|
|
|
|
Tdata returns an entire single dimension byte array.
Adr is the memory address, in this instance eeprom memory address: 0x02
Len is the length of the data bytes[8]
256 was just the standard number for an array declaration, In all reality and practicality
byte[] Data = new byte[256];
could just be
byte[] Data = new byte[8]
The byte[8] is then run through the for i=.... loop to convert the array from bytes to string.
|
|
|
|
|
This assumes that the result actually is 256 bytes. I suspect that
Marshal.Copy(result, data, 0, len);
might actually be what is wanted here.
The original code seems poorly written, Data is initialised and then assigned to, making the initialisation step pointless.
|
|
|
|
|
The error is on 'DLL.Receive' I assume?
What is the actual declaration of the target function in C? I suspect that Delphi is marshalling the result type automatically in some way and C# is not doing the same thing, and the result type isn't actually byte[] (it is probably byte*). Marshalling pointer types requires a bit more work in .Net.
|
|
|
|
|
Correct, Error occurs at Receive(Adr,Len)
The Delphi version as posted in the original entry, works fine with the Delphi example.exe calling the Delphi.dll. There is a Send(Data[],Len) routine as well that works fine in both Delphi and its converted C# version.
I have not explored the byte* route yet, perhaps it may offer a solution.
|
|
|
|
|
I'm having procedure with following fields e.g.(Previous.Balance, Debit, Credit )
Now in crystal reports. I want report structure like an account statement e.g. bank statement.
Description Dr Cr. Balance
Opening.. prevBalance
transaction 1 10000 prevBalance+Dr-Cr
transaction 2 5000 upperBalance+Dr-Cr
transaction 3 5000 upperBalance+Dr-Cr
How to achieve this type of running total in crystal reports in VS2010.
Regards.
Asif Rehman
|
|
|
|
|
Hello Everybody,
I want to create a List for Parent Child Information. So I want to know that what is the best Object for Store Information of Parent Child.
I am confused with :
Arraylist, IList,List,Distionery or
else in your mind.
If you have any example then your most welcome to share your knoledge.
Thanks
If you can think then I Can.
|
|
|
|
|
A List .
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Hello John,
Thanks for your suggession. Can u please help me How Can i Create a class that contain the information of Parant and Childs.
Thanks
If you can think then I Can.
|
|
|
|
|
As JSOP says, a List is probably the best.
However, there is the TreeNode class[^] which is used as part of teh TreeView class - this is already configured with Parent and Nodes properties, so it may be worth investigating.
If nothing else, they are easy to display - just add them into a TreeView...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
This would probably be the best way, but the parent/child relationship is kinda tenuous, and there's a lot of stuff in the TreeNode class that you don't need unless the collection is being displayed in a tree control. I think a carefully designed List would be more performant overall.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Thanks for ur suggession,
But i can't use treeview control because i am creating library without using Windows.Forms Controls .So pls help me for How i can work same as treeview.
Thanks
If you can think then I Can.
|
|
|
|
|
Try:
public class myTree
{
public myTree Parent {get; private set;}
public List<myTree> Children { get; private set;}
public myTree(myTree parent)
{
Parent = parent;
Children = new List<myTree>();
}
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
A List is very appropriate in this case. The other option is to create your own class.
|
|
|
|
|
The create your own class is a simple and nice implementation where the class contains a collection of children. That way the selected item contains pointers to the children, lazy or otherwise.
"You get that on the big jobs."
|
|
|
|
|
Yes, and I always prefer creating my own classes in such situations unless they're very trivial. Creating your own class gives you the freedom to model the class according to your requirements, decide between early and lazy loading children, restrict the type of children and their numbers to be added to a specific instance of the class, etc. With stock collection classes like List and Dictionary , you're forced to do this in an inefficient and ugly way.
|
|
|
|
|
What features should it have? If you want to easily get children from parent then a Dictionary<parent,List<child>> might be good, if you want to easily get parent from child, then a Dictionary<child,parent> might be good. If you want both, then you will likely want something custom.
|
|
|
|
|
You want a tree. A simple tree (with a single root node) can be created with a class like this:
class TreeNode {
IList<TreeNode> Children { get; private set; }
public TreeNode(){
Children = new List<TreeNode>();
}
}
If you want two way linkage you can do
class TreeNode {
IList<TreeNode> Children { get; private set; }
TreeNode Parent { get; private set; }
public TreeNode(TreeNode parent){
Children = new List<TreeNode>();
if(parent != null) parent.Children.Add(this);
Parent = parent;
}
}
Just store the tree through its root node, unless you want to store other metadata with the tree, in which case you can have a class like
class Tree {
TreeNode Root { get; private set; }
public Tree(TreeNode root){
Root = root;
}
}
|
|
|
|
|
Hello,
One of my friend ask me about how to use binding on multiple data sources.
Please help me to answer, as I am a newbie in .net programming.
|
|
|
|
|
This is gonna blow your mind:
9.7 MILLION google results for "bind control to multiple data sources"[^]
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I'm not sure I understand what you're asking. If you're talking about binding multiple data sources to a single control, I'm not sure it can be done without writing a custom control. For example, a select list can only have one data source. On the other hand, a custom control can have any number of elements that can be bound to their own individual data sources.
Scott E. Corbett
Software Engineer/Analyst
|
|
|
|