|
I have a similar question, Assume we have two Bitmap Images in a C# application, can we compare between them pixel to pixel ?
|
|
|
|
|
There's an article on the subject, right here[^] on CodeProject
--edit--
Forgot to answer the question: Yes, that's possible.
I are troll
|
|
|
|
|
hello good gurus.I've hesitated a lot before posting here coz i've been doing research(some of the articles here are too advanced for me ) but righ now i don't have the choice.it' seems that forum.hibernate.org is pointing to jboss for some reasons i don't know so please...
i'm new to nhibernate and i wanted to do a small application with 3 tables(i use 2 for now).table currency and table country here are the mapping files
<?xml version="1.0" encoding="utf-8" ?>
//country table mapping
<class name="dataprovider.Country,dataprovider" table="country">
<id name="CountryId" column="country_id" unsaved-value="0">
<generator class="native"/>
</id>
<!--<bag name="BatchList" inverse="true" lazy="true" >
<key column="country_id" />
<one-to-many class="Batch" />
</bag>
<bag name="PrinterList" inverse="true" lazy="true" >
<key column="country_id" />
<one-to-many class="Printer" />
</bag>-->
<many-to-one name="CurrencyId" column="currency_id" class="Currency" cascade="save-update"/>
<!--<property column="currency_id" name="Currency_Id"/>-->
<property column="name" name="Name"/>
<property column="region" name="Region" />
<property column="comments" name="Comments"/>
//currency table mapping
<id name="CurrencyId" column="currency_id" >
<generator class="native"/>
</id>
<bag name="CountryList" inverse="true" lazy="true" >
<key column="currency_id" />
<one-to-many class="Country" />
</bag>
<!--<bag name="DenominationList" inverse="true" lazy="true" >
<key column="currency_id" />
<one-to-many class="Denomination" />
</bag>-->
<property column="name" name="Name"/>
<property column="authorizer" name="Authorizer" />
<property column="date_created" name="DateCreated" type="DateTime" not-null="true" />
<property column="comments" name="Comments" />
the many to one relationship that country hold is an attribute of the type Currency in the country persistence class.Now while my test can_add_currency and can_add_country succeeded(i export the schema) i have null value in the table country on the field currency_id. here is the test code
<code>[Test]
public void can_add_new_country()
{
CountryManager cm = new CountryManager();
Country country = new Country();
//country.CurrencyId = CurrencyManager.GetCurrencyById(1);
country.CurrencyId = new CurrencyManager().GetCurrencyById(1);
country.Name = "POUND";
country.Region = "ENGLAND";
country.Comments = "the comment";
cm.Add(country);
using(ISession session = _sessionFactory.OpenSession())
{
Country fromdb = session.Get<Country>(country.CountryId);
Assert.IsNotNull(fromdb);
Assert.AreNotSame(fromdb, country);
}
}
public Currency GetCurrencyById(int currency_id)
{//GetCurrencyById from CurrencyManger class
try
{
using(ISession session = NHibernateHelper.OpenSession())
{
return session.Get<Currency>(currency_id);
}
} catch (Exception ex)
{
return null;
}
}
</code>
so the question is HOW TO INSERT INTO TABLE COUNTRY WITH THE CURRENCY_ID OF AN EXISTING CURRENCY_ID FROM THE TABLE CURRENCY? for example there is a currency with the currency_id=1, i want to insert to the country table and have currency_id=1 in the foreign key that is in country table.How you guys do it?i'm seriously stacked and 2 days small project is taking me one week now.Please have pity thanks for reading
eager to learn
|
|
|
|
|
Could someone please show me an example of how to create a registry entry using an API call to advapi32.dll. Basically make it do what the below .NET statement does.
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\ABCsoft\System\INIT", "SHARELOCATION", "C");
I have heard it can be done but haven't found any sample code to illustrate syntax.
Thank you so much for your time!
|
|
|
|
|
You're in luck: the essential registry functions reside in advapi32.dll
google for RegCreateKey, RegOpenKey, RegSetKeyValue
I stopped using most of them when .NET 2.0 started registry support.
Not sure why you want the trouble of finding the right combination and go through P/Invoke though.
|
|
|
|
|
I need to use the API because I will be having the users run the app from a mapped network drive. And too many users encounter a security exception when doing this. And I don't have the ability to modify the .NET config tool settings. So I have to do it the old fashioned way. Just don't know how format the syntax for those functions. Thanks.
|
|
|
|
|
OK, that is 2 issues:
1. running a networked app
for a .NET app, that could be an issue
2. accessing registry keys
I'm not convinced the old Win32 registry function would work when the .NET Registry class would prevent you from accessing the regkeys. And I expect it will be more strict on the latest Win versions (Vista, 7).
Are you saying you want to create a native app? didn't think so since you asked in this forum, C# is always managed and .NET
|
|
|
|
|
Thanks for your reply. Because the default setting for .NET is to prohibit writing to the registry when being run from a mapped drive. And I can't change .NET settings. I'm being forced to call API's. I know the API and function to use. Just not sure on how to use it. I know this can be done because I've run across web pages Calling API functions using C# that show it. So no, I don't want a native app. Just a Managed one that ALSO uses non managed code. The closest I've come is this --> http://pinvoke.net/default.aspx/advapi32.RegSetValueEx[^] but I'm still lost even with it. Thanks
|
|
|
|
|
I'm sorry to say but that article dates back 2001, it uses .NET 1.0 and AFAIK it's only reason of existence is .NET 1.0 did not have the Registry classes.
I doubt very much it will succeed in writing registry entries where normal .NET Registry classes (in existence since 2.0) would fail. However you can try that by downloading and running its code I guess.
|
|
|
|
|
OK, Thanks Luc. I didn't notice the date. I'll have to come up with another idea. But thanks for all your help.
|
|
|
|
|
you're welcome.
|
|
|
|
|
...with security issues like this though I can see why old timers are unwilling to try managed code.
|
|
|
|
|
It all depends. Do you want any EXE on a network, when double-clicked to start running and potentially delete your disk's content, change your registry, etc.
Microsoft is finally taking major steps in increasing security:
- .NET has its default permissions set low for all but the local drives;
- Vista (and Win7) are much more strict on file system and registry access;
- etc.
It is about time, if you ask me.
And yes, there is some pain since we got used to the more/too relaxed situation that existed till now.
|
|
|
|
|
Very good points. But yes, there is some pain. hehe.
|
|
|
|
|
You could also go directly for ntdll.dll, if it doesn't work with that then it's a sign that what you are trying to do amounts to hacking
|
|
|
|
|
Hacking? Oh for Pete's sake. What I want to do is so simple. If I knew C++ I'd have it done already I'm sure. But I'm trying to do it in c#. I do tech support. I want to be able to send a single executable file to a customer so I can easily make program setting changes WITHOUT guiding them thru using REGEDIT. Because .NET wont let me make those changes when running from a mapped drive, where the program whos settings are I want to change, sits. People have been programming using Win32 API's for years! All I want to do is make one call to bypass .NETS security. In my opinion, much safer than using the .NET configuration tool to open up ALL registry access.
Sorry, I'm just frustrated. If there is an easier way to make that registry change, TRUST ME, I would love to hear it.
|
|
|
|
|
you could use regsvr32.exe and feed it a .reg file
and you can automate that with a batch file or with the Process class.
|
|
|
|
|
Thanks,I wish I could. But a lot of what I would need to change or set would be dependent on different paths the client may be using. It would defeat my purpose. Be easier to just remote in and make the changes myself.
|
|
|
|
|
I don't understand, you could use a C# app to create a temporary .reg file and launch regsrv32 to execute it, couldn't you?
|
|
|
|
|
Now THAT, is not a bad idea! I little more work than i planed but, great idea! THANKS! But isnt regsrv32 used to register DLL files?
modified on Friday, April 17, 2009 9:06 PM
|
|
|
|
|
It started with a release build that failed to work.
Or actually it is a bit more subtle but it took a lot of work to find that out.
So, the story.
I'm writing a dll that is part of a bigger program. When I'm debugging it, it works fine, nothing wrong. But when I run the release build it first takes 100% cpu and after a while it crashes. This only happens if I run the release build - so neither when I try to debug the release build and ignore the warning that it's optimized, nor when I run the debug build directly without the debugger attached.
Have tried:
* copying the "debug" dll to the release folder of the exe (works)
* replacing all #if DEBUG by #if true (does not work)
* enabling full debug info for the release build (no effect)
* disabling optimization for the release build (works!)
But merely knowing this doesn't solve the problem. I'd like the code to be optimized.
So here is the real question: what is going on here? what could cause this?
I have a small amount of reflection going on, but nothing to serious, just things like enumerating custom attributes and calling a default ctor.. No dirty tricks with MSIL and Reflection.Emit. It does use SetWindowsHookExA but in a completely different part of the program than the failing part which shouldn't have any effect at all - but maybe it does? And it uses Xna.Framework and Xna.Framework.Game (but they should work, they always used to), which is why I'm compiling for x86 only (not AnyCPU).
|
|
|
|
|
harold aptroot wrote: it first takes 100% cpu and after a while it crashes.
Is there any specific error when it crashes?
Are you running the release build on your development machine? If so, you should get the option to attach the debugger only at the point of failure if attaching it before that point somehow doesn't show the error.
|
|
|
|
|
No it just goes unresponsive and windows asks me to close it.. I tried telling it to wait but it just goes on doing a lot of apparently nothing without any noticeable progress..
How do I attach the debugger to it? I remember seeing such an option in VC++, but I don't see it in VC# (I'm using Express now btw maybe that's why?)
|
|
|
|
|
Hi Harold,
do you have multiple threads? and cheap synchronization, say a bool variable set by one thread, read by another? forgot to apply the volatile keyword correctly?
in general: check your loops for things that, by optimization, might be pulled out completely making the loop empty and spinning forever.
|
|
|
|
|
A good suggestion and it was actually my first thought - but as far as I'm aware I only use ManualResetEvent 's for synchronization, and that should work shouldn't it?
Mostly it just spawns a few threads and then waits for all of them to finish (not many, say 3 to 8, doing a couple of seconds of work) and BeginInvoke /EndInvoke for some smaller tasks
But I'll recheck everything
|
|
|
|