|
So, this code:
using(BinaryReader reader = new BinaryReader(new FileStream("myfile.bin", FileMode.Open)))
{
string firstname = Encoding.ASCII.GetString(reader.ReadBytes(80));
string lastname = Encoding.ASCII.GetString(reader.ReadBytes(80));
}
returns the same value for firstname and lastname?
-- modified at 8:05 Wednesday 28th June, 2006
|
|
|
|
|
No. Firstname is the first 80 bytes. Lastname is the next 80 bytes.
|
|
|
|
|
The thing is, I simplified my question. In reality, the structure I am reading has a big list of vaiables of char arrays, and some ints and shortints. I was under the impression that I can somehow de-serialize it to eqiuvalent C# structure using some attributes or whatnot in System.Runtime.InteropServices. So I guess this is not the case?
|
|
|
|
|
Try to play with this code and see the file test.bin.
using System;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace ConsoleApplication22
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Test t;
t.firstname = "Hello".ToCharArray();
t.lastname = "World".ToCharArray();
using(FileStream fs = new FileStream("test.bin", FileMode.Create))
{
BinaryFormatter b = new BinaryFormatter();
b.Serialize(fs, t);
}
using(FileStream fs = new FileStream("test.bin", FileMode.Open))
{
BinaryFormatter b = new BinaryFormatter();
Test newt = (Test)b.Deserialize(fs);
}
}
}
[Serializable]
struct Test
{
public char[] firstname;
public char[] lastname;
}
}
|
|
|
|
|
That works in C#, i can read it no problem. C++ (non .NET) cannot read it properly.
|
|
|
|
|
That is a special formal from BinaryFormatter. It contains not only firstname and lastname, but also assembly name, etc...
|
|
|
|
|
Hi,
I am new to .Net. I developed a web application in ASP.Net and C#. Here I included a reference to Acrobat COM dll. I actually want to remove the toolbars from the PDF Document. But when I try to run the application, it throws a runtime error "Access Denied". I tried to register the COM dll using:
"regsvr32 Interop.Acrobat.dll". But here the error message is that: "the dll was loaded but entry point was not found".
To deal with the error "Access denied", I included "<identity impersonate="True">" in the web.config file. This helps run the application only on the server. When I try to run the application form a client, it throws a "runtime error" or "Server eror".
Can anyone suggest me a solution. Either how to run the application on clients using identity impersonate="true" or a solution to the Acrobat COM object.
I am facing a tough time and any help would be really appreciated.
Thanks,
Awase.
|
|
|
|
|
hi
how to streaming audio/video playback in windows application ?
do you know whether i should use wmplayer sdk ??
if yes how to do that ?
|
|
|
|
|
If you want to use WMPlayer supported formats and streaming protocols then yes.
Go here -> Clickety[^] for information to get you started.
The one adjustment is if you're running VS 2005 where you add the Windows Media Player component to the toolbox.
Line one reads "Right-click within the Toolbox and then select Add/Remove Items."
For 2005 it should be "...select Choose Items...".
Mike Poz
-- modified at 21:05 Tuesday 27th June, 2006
VS 2005 adjustment...
|
|
|
|
|
Hello,
For doing audio streaming u can use BASS[^]
regards,
Divyang Mithaiwala
System Engineer & Software Developer
|
|
|
|
|
Hello,
I currently have my application, which uses remoting to connect to the server. My problem is that if I change the assembly version on the server, the application will have trouble deserializing and the local copy of the assembly must be updated.
However, if I make very small changes to my app, I will only update the build and revision numbers, and not the major or minor versions. I would like my client and server apps to work if the major.minor version is the same, not taking into account the build.revision part.
I have found the bindingRedirect tag in the application config file, but a) it seems from the docs that when the app looks for a range of versions it will be ok to use a new version, and b) it seems to me that it is for loading assemblies locally, and not from remoting (altough I am not so sure about this.)
[EDIT: I tried bindingRedirect and it works as I expected. I will have to use two bindingRedirects , so that lower versions resolve to my version, and higher versions also resolve to my version. Now I'll have to change app.config for every build. No, that won't do it... and I also tried using an * instead of the revision number -- it didn't work either.]
BTW, my assemblies are strong named.
So, any ideas?
Thanks!!
Luis Alonso Ramos
Intelectix
Chihuahua, Mexico Not much here: My CP Blog!
-- modified at 20:59 Tuesday 27th June, 2006
|
|
|
|
|
Hi,
I am getting the name of the class from database as string. I want to create object for this class dynamically.
how do I do it?
|
|
|
|
|
Create a Type object from the name. Use the GetConstructor method to get a ConstructorInfo object for the constructor. Use the Invoke method to run the constructor.
---
b { font-weight: normal; }
|
|
|
|
|
Please can you show a sample code.
|
|
|
|
|
I explained exactly how to do it. Need I actually do it for you also?
---
b { font-weight: normal; }
|
|
|
|
|
|
That wasnt rude. It was simply "Give it a try yourself".
Teach a man to fish and all that.....
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
As well as the answer already provided, which will work no problem, you can also look at the CreateInstance method on the Activator class.
The documentation can be found on msdn.
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
Hi,
As well as the class name, you need to know what assembly the class is contained in. There are different ways of doing this, but just lifting a bit of code from work:
Assembly assembly = Assembly.LoadFile(@"c:\myassembly.dll");
object dynamicClass = assembly.CreateInstance(classNameFromDb);
Not sure that helps as you end up with an untyped object. The way we do it here is to make the objects we create dynamically implement an interface, so the second line actually looks more like
IDynamicObject dynamicClass = assembly.CreateInstance(classNameFromDb) as IDynamicObject;
This way, we can then call the methods the interface specifies.
After all, creating an instance of a class is little use if you have no idea what the object does. This is why defining an interface is useful.
And don't forget the gotcha, the trap I always fall in with this, its not just the type name you need, but also the namespace. eg. "MyNamespace.MyClass" which you need to pass to CreateInstance.
Regards,
Rob Philpott.
|
|
|
|
|
Hey Everyone,
I'm writing an app to test whether a serial port on a computer will work correctly and I'm using the principle of serial loopback.
I'm using the SerialPort class from System.io.ports and using a serial port object to write to the port and then listen to see if there was any data recieved. However, I always get a timeout for the recieve portion, even when I put the recieve method into a Thread.
Any ideas what I should try? Thanks in advance
-Karthik
|
|
|
|
|
Karthik Gaekwad wrote: I'm using the principle of serial loopback
I don't think you can use a principle I think you have to actually have a loopback.
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
led Mike,
You are correct. I am using loopback to solve the problem, but my recieve thread won't fire, even if I have the recieve wait for a message.
Hope that clears it up. Any suggestions?
-Karthik
|
|
|
|
|
And the solution is....
After you write to the port using a serial port object, use the readExisting method. DO NOT CLOSE THE PORT and then OPEN the port again to read. There is nothing stored in the buffer at that point.
I can be so dumb sometimes. That's what I get for trying to modularize my program.
|
|
|
|
|
Nice work, thanks for posting the solution.
|
|
|
|
|
Hello,
Directory.Exists(“\\localhost\c$”) and Directory.Exists(“\\localhost\SomeLocalShare”) and Directory.Exists(“\\127.0.0.1\c$”) and Directory.Exists(“\\127.0.0.1\SomeLocalShare”) all stop returning true once the network goes down. I know this seems obvious but how is it I can still resolve the local instance of SQL server? My question is how do I resolve a UNC name (assuming it is localhost) if the network is down, disabled, or non existent on Windows Xp pro and Better?
I was thinking of a virtual port maybe or a virtual Nic.
Any help will be very much appreciated
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|