|
Hello
I'm trying to pass a pointer array to a dll and get back and array of char **
I'm in the middle of the way because I already can get the first string pointed by my array
Concept : I pass an Id and a char ** to a DLL , the dll allocates his buffer and an internal char *array then assign that char * array to the passed pointer
What I do in Csharp
[DllImport("bcta.Dll")]<br />
static public extern int bctaGetName(IntPtr hBcta, UInt32 nAttID, ref IntPtr [] StrPtr);<br />
<br />
static public int TestName()<br />
{<br />
IntPtr hBcta = (IntPtr)0;<br />
UInt32 attrId = 1039;<br />
int count;<br />
IntPtr[] StrPtr = new IntPtr[8];<br />
<br />
bctaOpen(ref hBcta);<br />
attrId = 8967209;<br />
count = bctaGetName(hBcta, attrId, ref StrPtr);<br />
string aa = Marshal.PtrToStringAnsi(StrPtr[0]);<br />
bctaClose(hBcta);<br />
return 0;<br />
}
This is working fine for the FIRST string but my inPtr array is modfified by the DLL and it only contains 1 element at return however my count is 3
I miss something in the declaration but I can't figure out what ?
|
|
|
|
|
I strongly recommend wrapping native C/C++ DLLs in a mixed mode assembly using C++/CLI that then publishes one or more managed classes as an interface to pure managed languages. In this approach you can use native C/C++ to interface to the existing DLL simplifying the management of native types like pointers to pointers etc.
led mike
|
|
|
|
|
???? !
I'm sorry but I do not understand what do you my nor I can't see any solution to my current problem
I'm already using different function of that dll without any problem.
The problem here is how to declare an IntPtr to be modified by the DLL function
Example In C
char *ptr;
void function (char **ptr)
{
*ptr=calloc(10,sizeof(int);
}
|
|
|
|
|
baranils wrote: I'm already using different function of that dll without any problem.
Ok, good luck
led mike
|
|
|
|
|
Thank you
But your comments are not very usefull
This is how I do it in C
char **xptr;
bctaGetName (hBcta, id, &xptr);
// the ddl function will assign his own buffer to the adress so I can now read xptr[0],[1] etc...
// The question is HOW to do the same in Csharp (I can not declare a pointer to IntPtr) and if I give the ref of an IntPtr array I need to assign the Array before the call and that array will be lost into the call so only the first element will be usable !
|
|
|
|
|
I got it !!
Using pointer and unsafe !
static public unsafe extern int bctaGetName(IntPtr hBcta, UInt32 nAttID, out IntPtr** StrPtr);
unsafe static public int TestName()
{
char ch = (char)1;
IntPtr hBcta = (IntPtr)0;
UInt32 attrId = 1039;
int status;
IntPtr** StrPtr;
Routing.bctaOpen(ref hBcta, Environ.RoutingDataPath, ch);
attrId = 8967209;
status = bctaGetName(hBcta, attrId,out StrPtr);
string aa = Marshal.PtrToStringAnsi((IntPtr)StrPtr[0]);
Routing.bctaClose(hBcta);
return 0;
}
|
|
|
|
|
I have a programming assignment:
Program to generate Three Address Code Implementation( Quadruple & Triple) of a Complete Program.
Languages: C# or Java
|
|
|
|
|
Ayo Awe wrote: I have a programming assignment:
Congratulations and good luck
led mike
|
|
|
|
|
Have Fun!
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I need that to.
Please send me the code, its urgent..
|
|
|
|
|
As you are posting here, and don't ask any specific question about the implementation, I assume that you just don't understand the assignment?
Don't you have any more information at all other than the one that you have given in your question?
If your google is broken, here's some basic information about the three address code concept:
Wikipedia: Three address code[^]
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
For some reason DateTime.DaysInMonth(2008, 4) returns 31, yet DateTime.Parse("2008-04-31") yields in a FormatException.. am i missing something here? or is this some sort of bug.
|
|
|
|
|
damianrda wrote: am i missing something here?
Yeah, how to create a subject line that is meaningful and descriptive.
only two letters away from being an asset
|
|
|
|
|
Running the line of code you just mentioned returned 30
<br />
MessageBox.Show(DateTime.DaysInMonth(2008, 4).ToString());<br />
<code><br />
<br />
Sorry not much help there but I just thought id give you the result of my test. Very strange that it is returning 31 - it doesnt seem possible.
|
|
|
|
|
Yeah, I assumed he fat fingered the date and meant March, but if you're talking about April - yeah...that's a problem ;D
|
|
|
|
|
Aside from the bad subject line, I'd say your problem is that its parsing your date assuming a YYYY-DD-MM format.
|
|
|
|
|
damianrda wrote: am i missing something here?
Yes what Mark said and the fact that those two methods you posted have nothing to do with each other so your post is like saying, for some reason you can eat potatoes yet jumping off a building will hurt you.
led mike
|
|
|
|
|
led mike,
How tall is this building everyones jumping off?, I hope its not too big..
Regards,
Gareth.
|
|
|
|
|
I want a method to return different data types or classes. For example, sometimes I want the method to return an integer and sometimes I want it to return a string. I can do this by letting the method return an object and then the calling function has to cast the object into the appropriate type. Can I somehow make the calling function automatically find out which class or types it belongs to and "cast itself" into the appropriate type? Basically, this is what I want to do:
object myObject = myMethod(); // Can return an int or a string, casted into an object
MessageBox.Show("" + (myObject.GetType()) myObject); // Should work for both int:s and string:s
I want the expression
(myObject.GetType())
to be interpreted as a cast. How can I accomplish what I want?
Note: I've simplied the problem in order to make it easy to understand. Using ToString won't solve my real problem.
|
|
|
|
|
That kinda defeats the point of a strongly typed language. why would you ever want to do that?
(As far as I'm aware a dynamic cast like that isn't possible. you wouldn't know at compile time what type of object it was, so all it could be assigned to would be an Object type, so you'd instantly lose the cast Feel free to correct me if anybody knows better)
You'll probably find your problem is better solved by redesigning the class hierarchy your using, or using Generics instead.
Post a bit more detail so I can try to understand why you need to do this.
Simon
|
|
|
|
|
if you know it can be either string or int, you can always try
if (myObject is string)
SlayFourInnocentSheep( (string) myObject );
else if(myObject is int)
MessageBox.Show("It is an int!");
betonglasermur.FeedDwarf(pur_is, 17);
ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);
Morgonen är tröttmans mecka
|
|
|
|
|
This sounds like a job for Generics. Are you on a 2.0 or above platform? If not you should be. If you are then study Generics.
led mike
|
|
|
|
|
Thanks for your suggestions. I tried to use Generics, but couldn't get it to work. However, I should probably start a new thread for that problem.
modified on Wednesday, April 2, 2008 7:56 AM
|
|
|
|
|
Hi,
In C#, How to check current date falls between start date and end date.
start date and end date are defined in Database. so I want to check whether current is in between start and end date.
Can any one help me.
Thanks.
|
|
|
|
|
// Load start date and end date from database.
if(currentdate > startdate && currentdate < end)
{
// current date is between start and end date.
}
else
{
// It's not.
}
[EDIT]
(You can get the current date by doing DateTime.Now)
[/EDIT]
Simon
modified on Tuesday, April 1, 2008 12:26 PM
|
|
|
|