|
Whatever I do it always returned null!
|
|
|
|
|
I realize this is a little old, but maybe this will help others. My code is in VB but does not take much to convert to C#.
In XP this code takes and saves a picture:
item = dev.ExecuteCommand(CommandID.wiaCommandTakePicture)
Dim myImage As WIA.ImageFile = CType(item.Transfer(format), WIA.ImageFile)
myImage.SaveFile("c:\somewhere\mypicture.jpg")
But in Vista "item" is ALWAYS NULL but it does take the picture on the camera.
here is my fix:
' get current image count
Dim cnt As Int32 = dev.Items.Count
'take picture
item = dev.ExecuteCommand(CommandID.wiaCommandTakePicture)
' insert this single if block
If IsNothing(item) Then
' Vista drops the ball here (and a lot of other places!)
' Loop for up to 10 seconds waiting for the image to appear on camera device
While dev.Items.Count = cnt And x < 10
System.Threading.Thread.Sleep(1000)
x+= 1
End While
If cnt = dev.Items.Count Then
'throw your exception here - no image arrived
Else
' we found the new image on the camera
' pull it into the "item" variable since Vista didnt
item = dev.GetItem(dev.Items(cnt - 1).ItemID)
End If
End If
' and the rest of the code is unchanged.
Hope that helps.
|
|
|
|
|
You know I got it to work with WIA1 but never the version WIA2.
Thats because I used WIA1 on XP and WIA2 on Vista.
I see what you are saying. I was always able to get the camera to take a picture, but it never assigned the picture to the item.
I see what you did. You just take the amount of pictures on the camera, make it snap a picture, then if item is null (which is always will be) loop for 10 seconds OR until the count changes on the camera. Then get the last picture.
Genius! I'll give it a try
|
|
|
|
|
I write new application server/client. I use TcpClient. When my server is listening and allow many computers connect. Example : My server have 50 computers client connected. I have problem when I want to send 1 message to all clients, I must use FOR/NEXT therefore It cost 5 seconds or more to send 1 message to 50 Computers client. Now I want to improve speed of send message, Please give me advice.
Please see code below
//Send Admin Message
public static void sendAdminMessage(string sMessage)
{
//ArrayList LIST_CLIENT contain all connections of client
if (LIST_CLIENT.Count > 0)
{
Object []arr = LIST_CLIENT.ToArray();
for (int i = 0; i < arr.Length; i++)
{
try
{
MyClient client = (MyClient)arr[i];
send(client.TcpClient, sMessage);
}
catch(Exception e) {
Console.WriteLine(e.Message);
}
}
}
}
|
|
|
|
|
If you have the bandwidth, you could send each message on a seperate thread.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
you should use 2 threads for each client + 1 thread for entire network.
thread1)its priority should be low till they get a message from application in their line(collection for messages, you should build a class for that).
when message(s) got finished the priority should be set to low
thread2)should always read streams and add them to the line class associated with it.
net thread) should read lines of messages gotten by second set of threads and execute them.
i have did it and it worked very well.
i had a project i named it remotecompiler the project sends codes objects events procedures gets services from clients or server such as NetService FileService... (i used IServiceProvider class) and can execute orders with its services (it had about 50 classes)
i think tis may get you a good idea.
please tell me when you done it
|
|
|
|
|
How can I intercept the audio output as it goes to the sound card? is there an audio stream that I can access using .net or third party library?
I'm trying to write a program for correcting lip sync problems when playing back blu-ray discs. I'm hoping to be able to intercept the audio output from the computer and then add an adjustable time delay before sending it back to the audio output again.
Is this possible?
Cheers
|
|
|
|
|
I would imagine you're going to play with DirectX to intercept the audio stream and introduce a delay. I don't know exactly how you'd do that, tho
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Google this name, "Total Recorder".
They sell a library that lets you intercept the audio stream.
However, it doesn't work with Vista because Vista has a protected audio stream.
|
|
|
|
|
Richard Andrew x64 wrote: Google this name, "Total Recorder".
They sell a library that lets you intercept the audio stream.
However, it doesn't work with Vista because Vista has a protected audio stream.
Thanks, I've had a look at Total Recorder, the latest version does work with vista athough it seems that all I can do with it is duplicate the audio stream as it is output rather than being able to actually reroute it. I might be wrong of course.
What I would really like to be able to do is capture the audio stream before it gets to the sound output device and then add my delay before sending it on again.
|
|
|
|
|
I have come accros another issue whist trying to use directx to acheive my goal. I thought I would start by attempting to identify what the sound output device was identified as so I wrote the following to hopefuly display all my sound devices.
DevicesCollection devList = new DevicesCollection();
foreach (DeviceInformation device in devList)
{
Console.WriteLine(device.ToString());
}
Unfortunately running this code reulted in the following error.
LoaderLock was Detected
DLL 'C:\Windows\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll'
is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a
DllMain or image initialization function since doing so can cause the application to hang.
I've never come accross this before and have absolutely no idea how to resolve it. I'm a bit of a beginner having completed only 1 year of a computer science degree course so far and errors like this just tend to floor me.
|
|
|
|
|
|
hi,
i need to convert an ascii byte array to string.
in the byte [] could be 0 value that marks the end of the string.
i tried to do it like that :
byte[] test = { 0x41, 0x42, 0 };
string mystr = ASCIIEncoding.ASCII.GetString(test);
but the result is - "AB\0"
can i do it otherway to get just "AB" ?
thanks,
Samy
|
|
|
|
|
mystr.TrimEnd('\0');
Eslam Afifi
|
|
|
|
|
tried but doesn't work - still is the same. seems like the trim has no effect
|
|
|
|
|
mystr = mystr.TrimEnd('\0');
|
|
|
|
|
Of course it won't change the string it will return a new one. Strings are immutable. Sorry if the answer wasn't clear enoguh. PIEBALDconsult provided a full answer, and so did many others.
Eslam Afifi
|
|
|
|
|
This works (I tested it):
byte[] test = { 0x41, 0x42, 0 };
string mystr = ASCIIEncoding.ASCII.GetString(test);
if (mystr.EndsWith("\0"))
{
mystr = mystr.Substring(0, mystr.Length - 1);
}
Natza Mitzi
|
|
|
|
|
If you trying to convert a byte array to string, stopping on the first null, then try:
byte[] ab = { 0x41, 0x42, 0x43, 0, 0x44, 0x45 };
StringBuilder sb = new StringBuilder(ab.Length);
foreach (byte b in ab)
{
if (b == 0)
{
break;
}
sb.Append((char) b);
}
string s = sb.ToString();
I don't know of a built-in way to do it (though I have been wrong before).
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I thought Marshal.PtrToStringAnsi did that.. You have to give it a pointer though, so you need unsafe code.
|
|
|
|
|
I told you I could be wrong! Not too happy recommending unsafe code for this task, though - I prefer to keep it for when I need it (like converting strings to secure strings)
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
That just sounds ironic...needing "unsafe" code to create "secure" strings
Dybs
|
|
|
|
|
I know what you mean!
The problem is that managed (or safe) strings are duplicated, copied and may (or may not) be deleted - the unmanaged (or unsafe) stuff is more under your control, and thus "safer". I blame Microsoft for not introducing a "Secure" keyword for variables...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I probably wouldn't use it either (seems a bit like a canon to kill an ant, right?) but it exists
|
|
|
|
|
Hi,
GetString converts all the bytes from ASCII to Unicode, and 0 is a valid character, it is ASCII NULL.
If you know there is a NULL, then use ASCIIEncoding.ASCII.GetString(test, 0, test.Length-1);
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|