|
Hi,
1.
myInt.ToString("X8") turns an int into an 8-digit hex string;
and File.AppendAllText(filename,text) appends some text to a new or existing file
(there are faster ways with File.AppendText if lots of texts need appended).
2.
There are two explicit ways to get a pointer (to array or some other object); one is with the fixed keyword, the other with GCHandle, like so:
int dim=1000;
int[] numbers=makeIntArray(dim);
GCHandle handle=GCHandle.Alloc(numbers, GCHandleType.Pinned);
int sum=SumArray(handle.AddrOfPinnedObject(), dim);
handle.Free();
[DllImport("NativeC.dll")]
public static extern int SumArray(IntPtr pNumbers, int count);
3.
You do have native code that successfully calls the native lib, you said?
so you can read the calling code and understand exactly how it needs to be called, e.g. who is allocating the array.
If unclear, you could post some of that too.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
3.You do have native code that successfully calls the native lib, you said?
so you can read the calling code and understand exactly how it needs to be called, e.g. who is allocating the array.If unclear, you could post some of that too.
I have mentioned the native codes dll function signature, and how the native code calls it in my first post, if that's what you mean.
BTW I also found this http://msdn.microsoft.com/en-us/magazine/cc164193.aspx[^] article, with the mentioned PInvoke Interop Assistant application I got the result for this signature:
unsigned int func(unsigned __int16 arg1, unsigned __int16 arg2, unsigned __int16** arg3);
as this:
[System.Runtime.InteropServices.DllImportAttribute("<SomeDLL.dll>", EntryPoint="func")]
public static extern uint func(ushort arg1, ushort arg2, ref System.IntPtr arg3);
Which is exactly what you mentioned earlier. Have you used this application? If you have, what is your opinion about it?
I'll get back to you with the results for points 1 and 2.
Appreciate your suggestions.
|
|
|
|
|
I created an int array of size 1000 and initialized it from 0-999. Then I passed its GCHandle to the dll function. I changed the dll function signature to take the third argument as IntPtr. The array gets written to only in its first two indexes. With a kind of memory location address (not hex) or garbage value in index 0, and 0 in index 1 (everytime).
|
|
|
|
|
akhanal wrote: a kind of memory location address (not hex)
a number never is hex nor decimal, it is just a number; it is only input/output that turns it in to a string, which may be decimal, hex, binary, whatever you choose.
is the number a multiple of 4? if so, and probably is a pointer.
now do you have C code that successfully calls your func1?
can you make that work?
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Yes I have a c code that successfully calls the func1 in the dll and it is working as desired.
[ADDED]BTW do you know of any books that exclusively handles the interops (focusing on c#) and its shenanigans. Including but not limited to datatype marshaling, callbacks both ways, threading, P/Invoke, etc.[/ADDED]
Thanks
|
|
|
|
|
akhanal wrote: Yes I have a c code
Then show it here, so we can lift some doubts.
akhanal wrote: any books
No. Some articles yes. And I am in the middle of writing my own.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Here is the modified code for the function that calls func1(getList()) and other functions from the dll:
void listTheMembers(unsigned __int16 ID1, unsigned __int16 ID2)
{
unsigned __int16* arg3;
int i;
unsigned int test;
printf("\nMembers in list %d on server %d:\n", ID2, ID1);
if((test = getList(ID1, ID2, &arg3)) != 0)
{
printf("Error getting member list for %d: %d\n", ID2, test);
return;
}
if(!arg3[0]) {
printf("No members\n\n");
freeTheAllocatedMemory(arg3);
return;
}
for(i=0; arg3[i]; i++)
{
char* nameOfMember;
if((test = getName(ID1, arg3[i], Member_Username, &nameOfMember)) != 0)
{
printf("There was an error in querying member's username: %d\n", test);
break;
}
printf("%u - %s \n", arg3[i], nameOfMember));
freeTheAllocatedMemory(nameOfMember);
}
printf("\n");
freeTheAllocatedMemory(arg3);
}
The signatures for the called functions are:
unsigned int getList(unsigned __int16 ID1, unsigned __int16 ID2, unsigned __int16** result);
unsigned int freeTheAllocatedMemory(void* ptr);
unsigned int getName(unsigned __int16 ID1, unsigned __int16 MemberID, size_t flag, int* MemberName);
No. Some articles yes. And I am in the middle of writing my own.
That's great, it will be awesome to read one.
modified on Tuesday, September 29, 2009 11:11 AM
|
|
|
|
|
seeing the real function name, and example code using it, I now know the native function is allocating an array and setting its pointer through arg3 (which you later must free again). So you don't need any fixed nor GCHandle and this code of yours[^] should be pretty close. However your int [] managedArray = new int[1] is still wrong, they are 16-bit numbers, so use short!
Check again in the way I indicated here[^].
When in doubt, compare results for a native caller and your managed caller.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I am receiving following values in the index 0 of the array, and index 1 is always 0:
504150240
504150256
504150272
504150288
504150880
504150896
504150912
504150928
504150944
504150960
It looks like address values.
|
|
|
|
|
That most probably isn't hex as I see 9 digits (for a 16-bit number???); it takes hex to get maximum probability of seeing a pattern if there is one.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
This is the actual value and its hex equivalent for the 0th index of the array. I printed these values in a file like this:
System.IO.File.AppendAllText("c:\\projectLog.txt", Array[0].ToString());
System.IO.File.AppendAllText("c:\\projectLog.txt", ":");
System.IO.File.AppendAllText("c:\\projectLog.txt", Array[0].ToString("X8"));
System.IO.File.AppendAllText("c:\\projectLog.txt", Environment.NewLine);
505119136:1E1B81A0
505119552:1E1B8340
505140416:1E1BD4C0
505140432:1E1BD4D0
505140448:1E1BD4E0
505140464:1E1BD4F0
505140480:1E1BD500
505140496:1E1BD510
505140512:1E1BD520
505140528:1E1BD530
505140544:1E1BD540
505140560:1E1BD550
Here is to elaborate (remember I initialized the array[1000] with values 0 to 999):
Index 0: 486734960 : 1D02FC70 , Index 1: 0 : 00000000 , Index 2: 2 : 00000002
Index 0: 486734976 : 1D02FC80 , Index 1: 0 : 00000000 , Index 2: 2 : 00000002
Index 0: 486734992 : 1D02FC90 , Index 1: 0 : 00000000 , Index 2: 2 : 00000002
Index 0: 486735008 : 1D02FCA0 , Index 1: 0 : 00000000 , Index 2: 2 : 00000002
Index 0: 486735024 : 1D02FCB0 , Index 1: 0 : 00000000 , Index 2: 2 : 00000002
Index 0: 486735040 : 1D02FCC0 , Index 1: 0 : 00000000 , Index 2: 2 : 00000002
Index 0: 486735056 : 1D02FCD0 , Index 1: 0 : 00000000 , Index 2: 2 : 00000002
Index 0: 486735072 : 1D02FCE0 , Index 1: 0 : 00000000 , Index 2: 2 : 00000002
Index 0: 486735088 : 1D02FCF0 , Index 1: 0 : 00000000 , Index 2: 2 : 00000002
Index 0: 486735104 : 1D02FD00 , Index 1: 0 : 00000000 , Index 2: 2 : 00000002
modified on Tuesday, September 29, 2009 12:10 PM
|
|
|
|
|
OK, these clearly are pointers, they are multiples of 16, and ascending.
And your C code needs to pass one of them to get a member name.
You still have lots of details wrong, e.g. pointers cannot be int16, yet you declare arg3 as int16 pointer.
FYI: I retire from this thread; it has taken you till now to not tell what it is about, to provide real function names, and to mostly ignore what I have replied before.
You still have a lot to learn, I suggest you read a couple of books first.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
You still have lots of details wrong, e.g. pointers cannot be int16, yet you declare arg3 as int16 pointer.
That is not my code, it is part of a propriety SDK that I received to work with. And I am under obligations not to release the code (might get fired ). And that SDK has the int16 implementation.
I retire from this thread
I am sorry to hear that.
it has taken you till now to not tell what it is about, to provide real function names
Well you now know why.
mostly ignore what I have replied before
That's not true I have used almost all of your suggestions, and learned a lot in the process.
You still have a lot to learn, I suggest you read a couple of books first.
That is very true, that is why I was asking you about the particular book (If you have any suggestions in this regard it will be helpful). Thank you very much for all the time and efforts you have put on this. I appreciate it a lot.
|
|
|
|
|
I am trying to get the seleted radioButton from a group of radio buttons.
The program is supposed to check on the database for controls that match the selected radiobuttons. The radiobuttons are named High,Medium,Low.
For example
If a person selects High, the program must go through the database and choose all the controls that are rated High and then must load them into a listBox.
My problem is that the code i am using does not see the selected items and does not load the listBox.
I am usig SQL server database and stored procedures to do this.
Any suggestions on how i can go about doing this will be appreciated.
|
|
|
|
|
Not sure if you are doing this in a web page or in a rich client. In a rich client application it is very easy:
Create your group and put all radio buttons in there.
Bind all buttons to a single event handler.
In the event handler write something like this:
foreach ( RadioButton item in myGroup.Controls)
{
if ( item.Checked )
{
}
else
continue;
}
Now for the not-so-rich-and-pissy web interface you should confirm that all of your radio buttons have AutoPostBack=true and see if that helps your situation.
|
|
|
|
|
Hi everyOne.
I am useing Crystal Report in my project and its working well in my computer.But when i inistall it on user's Computer befor starting the program a Message(Need the crystall report be installed) is showen.
When i install crystalReport i work.
I do'nt want to install CrystalReport.What should i do?
Thank u .
CanI
|
|
|
|
|
Roya Rayane wrote: I do'nt want to install CrystalReport.What should i do?
Don't use Crystal Reports.
only two letters away from being an asset
|
|
|
|
|
hi dude,i cant exactly tell u what to do,but i think u should install that version of crystal which is required during setting up ur application.i think u can do it by INSTALLSHIELD ,hope that'll help.
good luck
|
|
|
|
|
Hi
you can add custom prerequisite in your setup application.
|
|
|
|
|
hi all
i wount To Select Row in DataGridView By Using Code C#
the Selected is Physically .
thanks
Thaer
|
|
|
|
|
Thaer Hamael wrote: Selected is Physically .
I suppose this would work better than trying to do it mentally, unless your Stephen Hawking.
Have you even tried searching for an answer or do you expect everyone else to do your work for you? This is something that just about any article on DataGridView should cover.
only two letters away from being an asset
|
|
|
|
|
Thanks Mr
I did not ask to suspend
But asked for help
If you can not help me I would not Alngliq of no benefit
I did not ask for assistance only after the test, Mr.
Thanks
Thaer
|
|
|
|
|
Take it easy there my friend..
Mark is simply saying you could have googled this, but just to get you started
the functionality you require is hidden away under :
DataGridView.Rows[rowindex].Selected = true;
On another note, people won't help you if your're rude.
Regards
Mick Curley
|
|
|
|
|
I'm not rude
I asked and one of them helped me to suspend
The answer obtained by you I know it , but the line chosen not be true only if chose by the mouse
Thanks
Thaer
|
|
|
|
|
Your question did not translate well to English so it may be difficult for anyone to answer.
|
|
|
|
|