|
A card reader emulates a keyboard - any DOS text program can accept input from one. I used to have fun with customers at Ace Hardware when I worked there for a while by opening Notepad, scanning their credit cards, and showing them exactly what information the stripes contained.
You should be able to use the CON device as input for a text stream, and capture the data from that. I've never tried it, mind you, but that's where I'd start looking. When you solve it, this would make a nice article for CP, by the way. This is a useful bit that many members would probably find helpful.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
How can I get list of Application Domains?
Following code not get created domain when call from different Win Application.
private static AppDomain GetAppDomain(string pFriendlyName)
{
IntPtr p_Handle = IntPtr.Zero;
//CorRuntimeHostClass Assembly --> C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscoree.tbl
CorRuntimeHostClass runtime = new CorRuntimeHostClass();
try
{
runtime.EnumDomains(out p_Handle);
do
{
object domain = null;
runtime.NextDomain(p_Handle, out domain);
if (domain == null)
{
break;
}
AppDomain appDomain = (AppDomain)domain;
if (appDomain.FriendlyName.Equals(pFriendlyName))
{
return appDomain;
}
} while (true);
}
finally
{
runtime.CloseEnum(p_Handle);
Marshal.ReleaseComObject(runtime);
runtime = null;
}
return null;
}
|
|
|
|
|
You can get a list of the application domains by formatting your bloody code when you post it!!!
|
|
|
|
|
dataminers wrote: Following code not get created domain when call from different Win Application.
That code works, but only for AppDomains created from your executable. AFAIK, it won't retrieve the AppDomain of another process. You can test it by feeding it AppDomain.CurrentDomain.FriendlyName , you'll see that it returns the current AppDomain.
Are you trying to use it for communication between two applications?
I are Troll
|
|
|
|
|
Actualy I want to create singleton class for each application. (Cross AppDomain Singleton)
|
|
|
|
|
How about a Mutex [^] instead?
I are Troll
|
|
|
|
|
How can I create cross appDomain singleton class using with Mutex?
I think Mutex Class not related about my problem.
Best Regards...
|
|
|
|
|
dataminers wrote: Following code not get created domain when call from different Win Application.
It's not allowed to simply "peek" in the memory of another application. You can retrieve a reference to any AppDomain within your application, but you'd have to use some form of interprocess-communication if the data has to cross the application boundary.
dataminers wrote: I think Mutex Class not related about my problem.
You said you wanted a singleton; you can create on by setting a mutex in the constructor, and releasing the mutex in the destructor. There are lots of other ways to ensure that only a single instance is created, but this would be my favorite
I are Troll
|
|
|
|
|
Following two class in the ClassLibrary
FIRST CLASS
using System;
using System.Runtime.InteropServices;
namespace MyLibrary
{
public class CrossAppDomainSingleton<T> : MarshalByRefObject where T : new()
{
private static readonly string AppDomainName = "Singleton AppDomain";
private static T _instance;
private static AppDomain GetAppDomain(string friendlyName)
{
IntPtr enumHandle = IntPtr.Zero;
mscoree.CorRuntimeHostClass host = new mscoree.CorRuntimeHostClass();
try
{
host.EnumDomains(out enumHandle);
object domain = null;
while (true)
{
host.NextDomain(enumHandle, out domain);
if (domain == null)
{
break;
}
AppDomain appDomain = (AppDomain)domain;
if (appDomain.FriendlyName.Equals(friendlyName))
{
return appDomain;
}
}
}
finally
{
host.CloseEnum(enumHandle);
Marshal.ReleaseComObject(host);
host = null;
}
return null;
}
public static T Instance
{
get
{
if (null == _instance)
{
AppDomain appDomain = GetAppDomain(AppDomainName);
if (null == appDomain)
{
appDomain = AppDomain.CreateDomain(AppDomainName);
}
Type type = typeof(T);
T instance = (T)appDomain.GetData(type.FullName);
if (null == instance)
{
instance = (T)appDomain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);
appDomain.SetData(type.FullName, instance);
}
_instance = instance;
}
return _instance;
}
}
}
}
SECOND CLASS
using System.Collections.Generic;
namespace MyLibrary
{
public class MySingleton : CrossAppDomainSingleton<MySingleton>
{
private List<string> m_List = new List<string>();
public void Add(string pValue)
{
m_List.Add(pValue);
}
public List<string> Get()
{
return m_List;
}
}
}
I ADD TWO WindowsFormsApplication TO MY SOLUTION, AND I ADD REFERENCE WHICH IS MYLIBRARY
I WROTE FOLLOWING CODE TO FIRST WINFORM
MySingleton.Instance.Add("test");
I WROTE FOLLOWING CODE TO SECOND WINFORM
List<string> res = MySingleton.Instance.Get();
BUT I CAN GET ADDED ITEM FROM FIRST WINFORM IN SECOND WINFORM
|
|
|
|
|
I have implemented my own "BitVecto64" class. I just wanted to have an indexer which would return a boolean value, use 64-bit integers, and have no length limit (eg. up to 64) - a true vector where all elements are from a set {0,1}.
The indexer is implemented as following (length of a vector unlimited, so I use an array of int64 insted of a single one):
public bool GetBit(int bit)
{
if (bit < 0 || bit >= BitCount)
throw new ArgumentOutOfRangeException("bit");
return (table[bit / BITS_IN_WORD] & CreateMask(bit)) > 0;
}
public static ulong CreateMask(int i)
{
return (ulong)1 << (i % BITS_IN_WORD);
}
My question: Is there any sens in caching masks? that is: {0x0, 0x1, 0x2,... ,0x10, 0x20,....0x100000...}. It would take 0,5 kB.
Greetings - Jacek
|
|
|
|
|
return (ulong)1 << (i % BITS_IN_WORD);
1. Should not be that slow that you have to do this.
But if you need to access it very often or in "long" loops I would cache it, because 0,5kB aren't that amount of memory.
Edit: After I took a deeper look I would say caching those values would be not faster than your function.
Thats because of the fact, that you have to do the modulo calculation (what consumes the most time in
part of code) also in the cached variant.
Here some pseudo asm that shows what I mean
CreateMask Version:
movzx rax, bit
xor rdx, rdx
div 64
mov cl, dl
movzx rax, bit
shl rax, cl
In this code div is the slowest instruction, all other intructions are very fast!
Cached Version: (I assumed that the cached items are seq. stored in the memory)
movzx rax, bit
xor rdx, rdx
div 64
shl rdx, 3
add rdx, (pointer to the "table" in memory)
mov rax, [rdx]
As you see there is no real difference between both!
2. You have build an 64 bit indexer to be not so limited but on the other hand you have limited your GetBit function only to be able to access 2147483648 bits!
So I would guess you should use public bool GetBit(long bit) instead of public bool GetBit(int bit) .
Greetings
Covean
modified on Friday, January 15, 2010 5:47 AM
|
|
|
|
|
Covean wrote: limited your GetBit function only to be able to access 2147483648 bits!
It is much more than I need (262,144 MB). However since there're 64-bit systems here and there, I can do this without any penalty and gain access to 2,25 Exabytes (1000 000 TB). Or at least change it to uint.
Greetings - Jacek
|
|
|
|
|
I just found it funny to not be limited and then limit the get function to int.
Here are some ideas to increse the performance.
1. BITS_IN_WORD == 64 correct?
If so just do return (ulong)1 << (i & 0x000000000000003F); instead of
return (ulong)1 << (i % BITS_IN_WORD); because [x mod 64] == [x and 0x3F] (with the last 6 bits (2^6 = 64) set to 1 all others to 0).
2. You could inline the function CreateMask in GetBit.
Greetings
Covean
|
|
|
|
|
Covean wrote: I just found it funny to not be limited and then limit the get function to int.
Right, I should think forward -- maybe some time we will measure memory in peta- or exa-bytes .
Covean wrote: return (ulong)1 << (i & 0x000000000000003F);
Nice, thanks... (no, not nice in a south park meaning[^]).
Greetings - Jacek
|
|
|
|
|
Cool video, thanks for that.
Greetings
Covean
|
|
|
|
|
Covean wrote: mov cl, dl
movzx rax, bit
This is a real pain in C# - we have to do div and mod seperately and therefore do the same operation twice, since cpu returns both values from div command.
Greetings - Jacek
|
|
|
|
|
Another mark: << operator can be used only for ints or smaller types. For uint/long/ulong it produces compile-time error .
Greetings - Jacek
|
|
|
|
|
Jacek Gajek wrote: << operator can be used only for ints or smaller
not correct; you can do long << int which is what you need; simply do the AND instead of the modulo, cast to int, then shift.
optimum = no table, no method, just a few in-line statements.
|
|
|
|
|
Jacek Gajek wrote:
My question: Is there any sens in caching masks? that is: {0x0, 0x1, 0x2,... ,0x10, 0x20,....0x100000...}. It would take 0,5 kB.
Only on old CPU's that don't have a single cycle shift by cl
Also, I would really ditch the % and / and use & and >> instead. The optimizer of the JIT compiler does optimize divisions and modulo's by constants, but for signed integers (even when it's trivial to prove that they can not be negative at that point) it wants to perfectly match real modulo en real division (which is not needed since it's not going to be negative anyway)
like: return (table[bit >> 6] & (1ul << bit)) != 0
edit: removed the redundant & 63
|
|
|
|
|
I liked the previous version more
harold aptroot wrote: edit: removed the redundant & 63
Why redundant? What if bit=213? I should look at 21th bit of 3rd integer. That is, table[2] & (1ul << 21) ;
Greetings - Jacek
|
|
|
|
|
Bitwise shifts in C# do an implicit shiftamount & (BITSIZE - 1)
Actually x86's do that already by themselves, provided that you used the right operand size (which is always the case for 64bit shifts, but the JIT compiler emits the and instruction anyway)
|
|
|
|
|
Dear Developers..
I need to generate a (.acb) file,which ll be used in photoshop.
like other .acb files by photoshop.
I think i have to user dll which give methods to convert file in acb format..
Please give me some sugggestion,hints..!
Thanking you
|
|
|
|
|
hi friends!!
i just wanted to know is there a way to inflate a region in GDI+, i am creating a region
on runtime using mouse_up event, then i get the region ; now i want to inflate it how can a
acheieve it? i have tried matrixtransformation + scale, is there some other way??
Thanks in Advance
Samir
|
|
|
|
|
hi all
i want to compare two xml files. does any one having code for this.
any hint ????
thanks in advance
koolprasad2003
Rating always..... WELCOME
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|
|
hi,
Are both the files having same structure i.e common tags ,
in this case if you use a class serialization method to read this XML file it can be very handy! You can create the class object of each file and actually come to know which tag is having diffent data.. hope this helps u..
Best of luck
Samir
|
|
|
|