|
Hello
So recently i've been making a program that uses DllExport of "user32.dll". The program itself is running pretty ok but this warning always pops up.
Because it is a P/Invoke method, 'Form1.mouse_event(uint)' should be defined in a class named NativeMethods, SafeNativeMethods, or UnsafeNativeMethods
I tried already many times and watched a lot of examples but it didnt help me.
Here is the part of the code
namespace XXX
{
public partial class Form1 : Form
{
[DllImport ("user32.dll")]
static extern void mouse_event(uint dwFlags);
public Form1()
{
InitializeComponent();
}
private void keyPressAction(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = true;
System.Threading.Thread.Sleep(300);
Cursor.Position = new System.Drawing.Point(1000, 0);
mouse_event(0x002 | 0x004);
DC
|
|
|
|
|
It's just a warning that there is a convention for moving all P/Invoke calls into a class called one of the three listed there. While it's recommended practice, it's not actually going to cause a bug in your code that it's not in one of those classes. Pragmatically speaking, you can safely ignore this warning. What I would be more concerned with, if I were you, is the fact that your keyPressAction is going to block the UI thread for 300 milliseconds. That's a major design flaw.
This space for rent
|
|
|
|
|
Maybe he really hates fast typists?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This space for rent
|
|
|
|
|
Thank you
|
|
|
|
|
and blocking UI thread.... is a part of my plan
|
|
|
|
|
Your plan is to piss off your users?
This space for rent
|
|
|
|
|
|
Then - not to put too fine a point on it - you are an idiot.
You will annoy people and make them work hard to ensure that you have no access to their machine(s) again. If you could install this, what else might you install?
If you are in a corporate environment, you could end up with a dressing down, disciplinary action, possibly being fired. If these are your mates, then they won't trust you as much again.
You can do it, but we won't help: technically it's malware and we do not condone, support, or assist in the production of malicious code in any way, form, or manner. This is a professional site for professional developers.
If you want to know how to create such things, you need to visit a hacking site: but be sure to disable all firewalls and antivirus products first or they won't trust you enough to tell you.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: Then - not to put too fine a point on it - you are an idiot.
I did the same, years ago. Some coworker wondered why his CD-tray kept opening and closing on its own[^] while he was working. It's hard not to burst from laughing if someone looks for an exorcist.
OriginalGriff wrote:
If you are in a corporate environment, you could end up with a dressing down, disciplinary action, possibly being fired. Any corporate environment says that you should lock your PC if you leave the station. If you don't, then don't blame me for using the keyboard for reminding you of company-policy.
OriginalGriff wrote: If you want to know how to create such things, you need to visit a hacking site: Gag-applications are a very long way from hacking, and his source doesn't look like something to hijack a computer. Remember this one[^]? I'll bet you recognize it when you hover the link
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
omg, guys you never had an idea to make a prank on your college and send them harmless app to annoy them because its a part of joke or smth? im really sorry for you if you don't have this kind of relations on your working place , you know job is not only about being serious and doing the apps and writing codes for working purpose only.But thanks for reply and answer
|
|
|
|
|
The first ever computer virus started out as a prank: The 30-year-old prank that became the first computer virus • The Register[^]
ILOVEYOU[^] was "accidentally" released - and cost an estimated $15 billion dollars worldwide (and the authors only escaped prison because they lived in the Philippines which had no laws against harming computers - they do now).
When young idiots do things they don't fully understand, they don't always realise - or even consider - the impact their actions will have. Often they don't even intend it to do what it does. Doesn't matter - intent is not the criteria, effect is.
Think about it:
Would you like it if you are slaving away to finish a project before the submission deadline and your computer started making impossible to continue?
Would your tutor accept "my mate f*cked my computer up" as a reasonable excuse for not handing it in?
Would you be a happy bunny if your mate messed up your computer?
I'm guessing here, but the answers are probably "no", "no", and "NO!".
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: The first ever computer virus started out as a prank So, you oppose taking a screenshot and setting that as the desktops background, because it could unleash powers equal to the tools stolen from the NSA?
OriginalGriff wrote: Would you be a happy bunny if your mate messed up your computer? Gag applications don't.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Eddy Vluggen wrote: Well written Gag applications don't.
FTFY
But given the skill level on show here - would you install a "gag app" from the OP on your computer and run it? I wouldn't ...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: But given the skill level on show here - would you install a "gag app" from the OP on your computer and run it? I wouldn't ... So, you agree that it is probably not some sophisticated virus?
If the gag-application errors out, what is the worst that is going to happen? The app crashing, probably. We help people with less skills that are working on production code with more impact. So yes, if I receive the code, I'd read a bit and run it on a test-PC.
I get more nervous if someone posts a question about software for hospitals; made me paranoid enough to opt out from one of their websites, based on the documentation I received.
You didn't answer the other question; are you familiar with the bit-recycler?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
No, it's not. But ... how many times in your career have you written code run it and gone "oh sh*t!" because it did something you really didn't mean it to? A db UPDATE with the wrong WHERE clause? Overwriting a file instead of appending it? Worse?
We all have. But if we muck up our PC that's one thing. Someone else's? Not the same at all.
And the lower the skill level, the more chance of error - you know that.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: We all have. But if we muck up our PC that's one thing. Someone else's? Not the same at all.
And the lower the skill level, the more chance of error - you know that. Dude, it is a nonsense-application. Every student starts somewhere. I have run many pieces of homework on this machine, but never did anything happen that caused damage.
Yes, I know the dangers of coding all to well, in my first year I created a bug that caused a machine to dump 3 cubic meters of quick-drying cement on the floor. The people that had to shovel it away were not amused.
A gag-application is usually not run on an important server, and even if he makes a mistake, I doubt it would be as destructive as a virus.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Eddy Vluggen wrote: I have run many pieces of homework on this machine, but never did anything happen that caused damage. I was working on a project at my last employment some years ago and managed to disable one of my drives completely, with a fairly unsophisticated MFC app. Had it been the C drive I would have been most displeased.
|
|
|
|
|
That's why we don't work on production environments.
Doesn't mean that people should stop writing code "because" they may make a mistake
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I never suggested they should.
|
|
|
|
|
So he really does hates fast typists!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You could try putting this at the top of your file:
#pragma warning disable 1060
Or you can add this attribute to the method prototype:
SuppressUnmanagedCodeSecurityAttribute
Or, you could simply obey the warning and create an appropriate class and put the interop methods in it.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 12-Mar-18 13:33pm.
|
|
|
|
|
|
I prefer to put all of my interop stuff into their own class. I think this warning started showing up in VS2017 (I've never seen it in VS2013).
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I'm starting to plan out a project and I need some help with ideas.
Situation: my company uses a software managed by a third party company. I do not know exactly how this works but the link to this program looks like "113.444.767.123/bin/some file". This is started though iexplorer then switches over from the iexplorer process to a different process (I have the name).
We recently had then create a test company for training purposes. I can make two separate desktop icons easy enough. But once the program is running, if both the training and real companies are running at the same time, it is hard to determine the difference.
I want to change the taskbat icon, and pop a message balloon when the user switches between the two.
First problem, windows will use the desktop icon before the app icon, so I'm going to create a bootloader app that is launched from the desktop, it will open my real app and kill itself. Now I will have access to change the taskbar icon through code.
Second problem, I can't just call the process the company program and follow the returned processId because the original iexplorer ID calls the other program, thus changing ID's.
My thoughts: when I start the process from my program I start a loop the constantly calls getProcesses and loops through each one until the actual program process name is found. Once found I'll have the ID off the correct process and can match up icons based on that.
Third problem monitoring what process is active to change the icons.
My thoughts were to use TPL tasks, start a new async task that runs a loop to get the ForgroundWindowGetID and compare it to the list of IDs for the program I'm tracking. This is were in a little murky, can I send the ID back to my main program to handle the icons and balloons while still keeping the async task running, or do I need to stop the async task when the ID changes, then restart the task?
|
|
|
|
|