|
Thanks Christian,
I appreciate your attempt here, but I'm afraid I'm too lost.
As I said to digitalKing above. I've literally spent the last 5 hours mired trying to pick apart the various methods to do this.
I have no doubt, there's probably at least a dozen ways and I'll bet I've tried 30.
I've been reading every book on my library on C# strings, pointers, how they work, what they don't do. Other classes, like StringBuilder, Marhsal, pinning, pinvoke
My brain is mush and all these terms are now just jumbled into one big mess.
What I need at this point is a simple example showing the csharp equivalent of the code I provided.
FTR, the actual API function I'm using is AVIFileWriteData() and I've also googled it and searched out every possible example, but that function is so rarely used (it writes ancillary information data into a AVI header) by anyone that nobody bothers to include it in their port of the AVI functions into .NET.
Trust me, there is no example of this particular functions use in managed code, but I really didn't think it made any difference, all I'm trying to do is make a string then pad it up to 2048 characters (I won't go into why it needs to be 2048, it just does) and then give this function a pointer to the data. Why does this have to be so hard?
regards,
Phil
|
|
|
|
|
It looks to me like if you create a byte array of 2048 bytes, and then manipulate it, you'll be able to do something like
unsafe
{
byte * bytes = myArray;
// pass the pointer in to your function
}
AVIFileWriteData appears to take an LPVOID, so it doesn't really matter what you pass it, so long as it's a pointer to the array in memory
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Yup, you're right, it really doesn't matter what I pass it so long as it's a pointer to the string memory.
But if I do it like you said then I have this myArray buffer that becomes difficult to print simple strings to.
ie. then I'm left with the question:
how to I format text into myArray?
My approach was to have MyFunction() encapsulate all this ugliness and just make a simple c# call inside my main program like:
string aviinfo = "[Timing] Frame Rate=250 Mark Frame=9";
PhilsFunction( aviinfo);
Inside Philsfunction is the ugliness of converting this simple ordinary c# string into a padded 2048 byte area of memory and delivering the pointer to AVIWriteFileData()
it's the conversion, padding and pointer part that has me stuck.
|
|
|
|
|
string s = "test this, sucka";<br />
ASCIIEncoding enc = new ASCIIEncoding();<br />
byte[] b = enc.GetBytes(s);<br />
<br />
unsafe<br />
{<br />
byte [] b2 = new byte[2048];<br />
Array.Copy(b, 0, b2, 0, b.Length);<br />
<br />
fixed (byte * send = b2)<br />
{<br />
<br />
}<br />
}
As far as I can tell, this starts with a string ( build it however you like ) and then turns it into a byte [], then it creates a second byte [], of fixed size, copies the contents of the first into the new array, then turns that into a fixed size pointer.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
OK, now that solution I definitely never would have come up with!
It does compile anyway. I had to modify my prototype to to to a byte * instead of an System.Intptr the way I originally had it (not a big deal, although it would have been nice to keep all the pointer types consistent throughout this class...all the rest of the API Functions were done that way).
Running the debugger does seem to show it working. The API function is throwing a nasty exception though, I'm not convinced it likes this byte pointer and I'm not sure how to browse memory to confirm this pointer is really pointing to my actual buffer of data.
I'm assuming you wanted me to call:
AviFileWriteData( ..., send, 2048);
In other words "send" is the pointer?
(obviously I've never used the fixed keyword before so this whole syntax is another new adventure).
I should be able to figure it out from here anyway.
At least I got the thing to compile. For me, that's 90% of it, I can usually tweak, adjust and debug from there.
thanks Christian
(P.S. this all still strikes me as a HUGE pain in the butt compared to the old C++ way, I'll never be convinced C# is better).
|
|
|
|
|
Phil C wrote: (P.S. this all still strikes me as a HUGE pain in the butt compared to the old C++ way, I'll never be convinced C# is better).
C# is plainly not 'better' It's 'better at certain tasks'. For example, if time is an issue, I'd prefer to work in C# than C++. If speed is an issue, it's gotta be C++. But really, it's potential to get messy definately increases when you need to do this sort of stuff to bridge the two.
I'm very happy to know C#, but I'll never abandon C++, even if I find myself using it a lot less nowadays.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
My exception fault was from a mistake on one of the other params - unrelated and I thought so when I first saw it.
This did work Christian. It's a bit ugly, but at least all the ugly stuff is isolated inside my AVI class.
I'd still be spinning my wheels if you hadn't stepped in. Thanks again. Now I can sleep
Phil
|
|
|
|
|
No worries, glad to help. To be honest, I only vaguely knew where to look for the answer ( hence my initial, vague comments ), so I was glad to look them up and learn it for sure, for myself.
I've actually never used the 'fixed' keyword myself, I've just read about it...
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Phil,
You can also try using the Marshal static functions.
For example:
<br />
string s = new string(" ", 2048);<br />
IntPtr ptr = Marshal.StringToHGlobalAnsi(s);
Then you can pass ptr to your method.
There are other helpful functions available in Marshal that you may be able to use such as: Marshal.AllocHGlobal, or Marshal.PtrToStringAnsi .
Regards,
Rudy.
|
|
|
|
|
Im having problems updating my grid. The grid loads fine, the edit button functions fine(bringing up textboxes)...I update the data....click "Update" and it reloads the grid. I think this is caused because my form load reloads the grid again but I can't seem to get my grid to show unless I do this.
Attached is my form load and update statement....(ps. it enters my update function but the text value is the pre-updated value)
<br />
public void Page_Load(Object sender, EventArgs e)<br />
{ <br />
_sqlStmt = "SELECT Nm as [Name], OfficeNm as [Office Name], HomePhone as Home, OfficePhone as Office, Address FROM contacts";<br />
oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\\db.mdb";<br />
oleDbDataAdapter1.SelectCommand.CommandText = _sqlStmt;<br />
dataSet1.Clear();<br />
oleDbDataAdapter1.Fill(dataSet1, "Contacts");<br />
BindGrid();<br />
}<br />
<br />
<br />
void BindGrid()<br />
{<br />
Trace.Write ("**IN_BindGrid");<br />
MyDataGrid.DataSource = dataSet1.Tables["Contacts"].DefaultView;<br />
MyDataGrid.DataBind();<br />
}<br />
<br />
<br />
public void MyDataGrid_Update(Object sender, DataGridCommandEventArgs e) <br />
{<br />
Trace.Write ("**In_MyDataGrid_Update");<br />
string Name = ((TextBox)e.Item.Cells[1].Controls[0]).Text;<br />
string OfficeNm = ((TextBox)e.Item.Cells[2].Controls[0]).Text;<br />
string Home = ((TextBox)e.Item.Cells[3].Controls[0]).Text;<br />
string Office = ((TextBox)e.Item.Cells[4].Controls[0]).Text;<br />
string Address = ((TextBox)e.Item.Cells[5].Controls[0]).Text;<br />
<br />
oleDbDataAdapter1.Update(dataSet1);<br />
BindGrid();<br />
}<br />
<br />
Any help is greatly appreciated....
-Kay
-- modified at 23:13 Saturday 6th May, 2006
|
|
|
|
|
Hi..
I want to use the CmdLoadFromResource() method of ths speech SDK 5.1 to make the xml file that includes the Grammar embeded but i dont know how to use this method in C#.
Does any one know how to use this method?
|
|
|
|
|
|
Could you give me a C# sample code for using P/Invoke with the method CmdLoadFromResource()?
|
|
|
|
|
How could I open an Acrobat document from C# program? I do not want to read and get data in program. Only want to open it from a link.
|
|
|
|
|
Use the Process class:
System.Diagnostics.Process.Start("C:\Document.pdf");
Hope that helps!
|
|
|
|
|
Hi,
I started a new thread in my project which will call a function inside a class. But the thread doesn't calling the function. What can I do?
The function, which work in a new thread is just the function used in RssReader Demo, a article in this forum. I want to do further processing the items retrieved by RssReader, so I put the function which will use the RssReader class in my class. Is it a problem?
Tahsin Sayeeda Moon
(B.Sc. in Computer Science & Engineering
Internation Islamic University Chittagong)
|
|
|
|
|
Tahsin Sayeeda wrote: What can I do?
Hard to say without seeing pertinent portions of your source code.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Hello Sayeeda,
When running a new thread, you have to first instantiate it, and then call the Start() method on the thread object you've instantiated.
You should do something like this:
Thread t = new Thread(/*Your parameters goes here*/);
t.Start();
Your thread will not start running the function until you call the Start() method.
Anyway... I think if you post some of your code here we could help you further than that.
Shy.
-- modified at 4:59 Sunday 7th May, 2006
|
|
|
|
|
Hi,
Actually after reading the rules of posting a question, I got afraid to send my code!
Here how I called the thread.
CNews cnews = new CNews();
Thread thread = new Thread(new ThreadStart(cnews.readRss));
thread.Start();
And here is the function inside CNews class
public void readRss()
{
RssReader rssReader = new RssReader();
rssReader.FeedLoaded += new EventHandler(rssReader_FeedLoaded);
rssReader.ItemAdded += new EventHandler(rssReader_ItemAdded);
rssReader.Error += new RssReaderErrorEventHandler(rssReader_Error);
RssFeed feed = rssReader.Retrieve("C:\\news.xml");
if ( feed.ErrorMessage == null || feed.ErrorMessage == "" )
{
int i;
for(i=0;i<itemsFound;i++)
{
ItemDescription[i] = feed.Items[i].Description;
}
}
}
I use the code from Rss Reader demo by smallguy78 as I previously mentioned. Please tell me if there is anything more I’ve to send from my code.
Actually the code runs okay in my main form. But I fail to get the value from it in my CNews class (using get and set properties). I have to do further processing with those values which I did in my class. So I put the function in my class. Then the thread doesn’t calling the function!
I can also send my full project if anyone interested I mean need to see it.
Tahsin Sayeeda Moon
(B.Sc. in Computer Science & Engineering
Internation Islamic University Chittagong)
-- modified at 14:43 Sunday 7th May, 2006
|
|
|
|
|
I've no idea what's this Rss Reader demo by smallguy78...
Would you post a link?
Shy.
-- modified at 6:54 Sunday 7th May, 2006
|
|
|
|
|
|
How did you conclude the thread is not getting called? Did you try, for instance, setting a breakpoint in readRss and checking if it got hit? And are you sure the code starting the thread is actually executing?
Regards
Senthil
_____________________________
My Blog | My Articles | My Flickr | WinMacro
|
|
|
|
|
Hi,
Actually I tried to call another function by the new thread. The function is in main form which will only show something in a text field. The nothing is showing in that field.
And I also set a breakpoint to see what’s going on, the thread starts but it doesn’t call the function. I can’t get into my demo function.
Tahsin Sayeeda Moon
(B.Sc. in Computer Science & Engineering
Internation Islamic University Chittagong)
|
|
|
|
|
Tahsin Sayeeda wrote: Actually after reading the rules of posting a question, I got afraid to send my code!
By just reading them, you are way ahead of most posters.
---
b { font-weight: normal; }
|
|
|
|
|
I always call Thread.Sleep(0) in the parent after starting a thread. There's an issue with uniprocessors not starting child threads if the main thread does not give up its time slice.
|
|
|
|