Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Trying to make my crosshair work.

Hey guys, I'm trying my luck at C# here. I'm more of a C++ guy, but learning doesn't hurt.

Right now, I'm trying to make a crosshair. Can you please review my code, and help me figure out where I'm getting the error on line 3? It would be appreciated.

Code
using System;using System.Runtime.InteropServices;namespace Crosshair{public static class Win32{public enum Bool{False= 0,True};[StructLayout(LayoutKind.Sequential)]public struct Point{public Int32 x;public Int32 y;public Point(Int32 x, Int32 y) { this.x = x; this.y = y; }}[StructLayout(LayoutKind.Sequential)]public struct Size{public Int32 cx;public Int32 cy;public Size(Int32 cx, Int32 cy) { this.cx = cx; this.cy = cy; }}[StructLayout(LayoutKind.Sequential, Pack = 1)]struct ARGB{public byte Blue;public byte Green;public byte Red;public byte Alpha;}[StructLayout(LayoutKind.Sequential, Pack = 1)]public struct BLENDFUNCTION{public byte BlendOp;public byte BlendFlags;public byte SourceConstantAlpha;public byte AlphaFormat;}[StructLayout(LayoutKind.Sequential)]public struct RECT{public int Width{get { return (Right - Left); }}public int Height{get { return (Bottom - Top); }}public int Left;public int Top;public int Right;public int Bottom;}public const Int32 ULW_COLORKEY = 0x0000001;public const Int32 ULW_ALPHA = 0x0000002;public const Int32 ULW_OPAQUE = 0x0000004;public const byte AC_SRC_OVER = 0x00;public const byte AC_SRC_ALPHA = 0x01;[DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]public static extern Bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref Point pptDst, ref Size psize, IntPtr hdcSrc, ref Point pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);[DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]public static extern IntPtr GetDC(IntPtr hWnd);[DllImport("user32.dll", ExactSpelling = true)]public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]public static extern IntPtr CreateCompatibleDC(IntPtr hDC);[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]public static extern Bool DeleteDC(IntPtr hdc);[DllImport("gdi32.dll", ExactSpelling = true)]public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]public static extern Bool DeleteObject(IntPtr hObject);[DllImport("user32.dll")]public static extern int FindWindow(string lpClassName, string lpWindowName);[return: MarshalAs(UnmanagedType.Bool)][DllImport("user32.dll")]public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);}}

Thank you in advance..

Edit: Wow, I figured it out a minute after posting. I was missing a } after { this.cx = cx; this.cy = cy; } so the code should have looked like { this.cx = cx; this.cy = cy; }}
Hopefully, this can be a reference to anyone else who encounters this issue in the future.
What the hell is that mess!

Look up how to make a DirectX overlay.
Or even XNA.
(May 7, 2014 10:30 AM)Tafelpoot Wrote:  This is probably the worst copy paste i have ever seen.

It's not a copy paste. It's my own format.

Edit: Unless you mean copy pasted from visual studio, then yes. But this is how I format my own code, sorry if there was a problem.


(May 7, 2014 09:52 AM)Cornflower Blue இڿڰۣ-ڰۣ— Wrote:  What the hell is that mess!

Look up how to make a DirectX overlay.
Or even XNA.

I know how to make a DirectX overlay. I'm no noob to programming. Why do I need XNA? It has nothing to do with what I -was- trying to achieve.
(May 7, 2014 10:45 AM)the best guy ever Wrote:  It's not a copy paste. It's my own format.

Edit: Unless you mean copy pasted from visual studio, then yes. But this is how I format my own code, sorry if there was a problem.



I know how to make a DirectX overlay. I'm no noob to programming. Why do I need XNA? It has nothing to do with what I -was- trying to achieve.

Assuming this is you're code, and according to the way you're "formating" (if it's even possible to call that formating), then sorry man, but you're a noob.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - Martin Fowler. I've never seen something that messy and horrible so far. Even javascript eval packed function are clearer than that

[Image: 1riOqZa.png]
Perhaps his messy code is a good thing.
Perhaps someone was to view the source of his program, and see that code.
Perhaps, the viewer will be swayed to stop.
;)
(May 7, 2014 11:53 AM)TreeTopSky Wrote:  Perhaps his messy code is a good thing.
Perhaps someone was to view the source of his program, and see that code.
Perhaps, the viewer will be swayed to stop.
;)

That's some nice thinking you got there! If only others did!👍

Noone viewed the source of my program, except you guys now! Except that's just a snippet that I needed help with, but I got it. Thanks again!
(May 7, 2014 10:45 AM)the best guy ever Wrote:  It's not a copy paste. It's my own format.

Edit: Unless you mean copy pasted from visual studio, then yes. But this is how I format my own code, sorry if there was a problem.



I know how to make a DirectX overlay. I'm no noob to programming. Why do I need XNA? It has nothing to do with what I -was- trying to achieve.

You're not a noob to programming but you cant draw an image on a screen? Seems legit.

Also, XNA is a wraper for DirectX, you can make a game overlay using XNA.
Thought I would just pretty print for all the lazy.

PHP Code

<?php 
using System
;
using System.Runtime.InteropServices;
namespace 
Crosshair
{
    public static class 
Win32
    
{
      public enum 
Bool
      
{
      
False= 0,True
      
}
      ;
      [
StructLayout(LayoutKind.Sequential)]public struct Point
      
{
      public 
Int32 x;
      public 
Int32 y;
      public 
Point(Int32 x, Int32 y)
      {
            
this.x = x;
            
this.y = y;
      }
      }
      [
StructLayout(LayoutKind.Sequential)]public struct Size
      
{
      public 
Int32 cx;
      public 
Int32 cy;
      public 
Size(Int32 cx, Int32 cy)
      {
            
this.cx = cx;
            
this.cy = cy;
      }
      }
      [
StructLayout(LayoutKind.Sequential, Pack = 1)]struct ARGB
      
{
      public 
byte Blue;
      public 
byte Green;
      public 
byte Red;
      public 
byte Alpha;
      }
      [
StructLayout(LayoutKind.Sequential, Pack = 1)]public struct BLENDFUNCTION
      
{
      public 
byte BlendOp;
      public 
byte BlendFlags;
      public 
byte SourceConstantAlpha;
      public 
byte AlphaFormat;
      }
      [
StructLayout(LayoutKind.Sequential)]public struct RECT
      
{
      public 
int Width
      
{
            
get
            
{
            return (
Right - Left);
            }
      }
      public 
int Height
      
{
            
get
            
{
            return (
Bottom - Top);
            }
      }
      public 
int Left;
      public 
int Top;
      public 
int Right;
      public 
int Bottom;
      }
      public const 
Int32 ULW_COLORKEY = 0x0000001;
      public const 
Int32 ULW_ALPHA = 0x0000002;
      public const 
Int32 ULW_OPAQUE = 0x0000004;
      public const 
byte AC_SRC_OVER = 0x00;
      public const 
byte AC_SRC_ALPHA = 0x01;
      [
DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]public static extern Bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref Point pptDst, ref Size psize, IntPtr hdcSrc, ref Point pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);
      [
DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]public static extern IntPtr GetDC(IntPtr hWnd);
      [
DllImport("user32.dll", ExactSpelling = true)]public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
      [
DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
      [
DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]public static extern Bool DeleteDC(IntPtr hdc);
      [
DllImport("gdi32.dll", ExactSpelling = true)]public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
      [
DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]public static extern Bool DeleteObject(IntPtr hObject);
      [
DllImport("user32.dll")]public static extern int FindWindow(string lpClassName, string lpWindowName);
      [return: 
MarshalAs(UnmanagedType.Bool)][DllImport("user32.dll")]public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
    }
} 
XNA is old and deprecated already, there's no future use for it.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(May 8, 2014 04:11 PM)0xDEAD10CC Wrote:  XNA is old and deprecated already, there's no future use for it.

It may not be getting anymore updates, but is it 'old' yet? I don't think so. Anyways, there's an open source version that continues to get updates: MonoGame
It's old news then, there's no sense in arguing the semantics here, technology is considered old a year after most devices first come out. The first stable release was 2 years ago, and the fact still remains that it is already deprecated... What old means to various people, is subjective, and I'm not here to debate that. That's silly.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(May 8, 2014 04:55 PM)0xDEAD10CC Wrote:  It's old news then, there's no sense in arguing the semantics here, technology is considered old a year after most devices first come out. The first stable release was 2 years ago, and the fact still remains that it is already deprecated... What old means to various people, is subjective, and I'm not here to debate that. That's silly.

DirectX 11 was released in 2009. DirectX 11.1 was released in 2012. That's a 3 year gap without any major updates. MonoGame's last stable release was a month ago, and the last stable release before that was about a year ago.
You're still not getting it... DirectX isn't deprecated, regardless of how many updates are made to it in X amount of time. MonoGame has built around the XNA framework. These statistics have no relevance to what I was pointing out. The XNA framework IS deprecated on the other hand, and you're comparing wrappers around XNA to the thing XNA was built around. How is that even logical? That's like comparing Windows programs to the Windows Operating System... At its core, although MonoGame has expanded, it uses XNA, which is an implementation or framework around DirectX.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
Who needs obfuscation when you can use this guy's "formatting"!
(May 8, 2014 05:41 PM)0xDEAD10CC Wrote:  You're still not getting it... DirectX isn't deprecated, regardless of how many updates are made to it in X amount of time. MonoGame has built around the XNA framework. These statistics have no relevance to what I was pointing out. The XNA framework IS deprecated on the other hand, and you're comparing wrappers around XNA to the thing XNA was built around. How is that even logical? That's like comparing Windows programs to the Windows Operating System... At its core, although MonoGame has expanded, it uses XNA, which is an implementation or framework around DirectX.

MonoGame is not a 'wrapper around' XNA; it IS XNA.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by Sir BillyAug 26, 2019 06:33 PM 1 150 Aug 26, 2019 06:33 PM
Last Post: YouthInAsia
[.NET] by RandomUser123Apr 19, 2015 11:11 AM 1 99 Apr 19, 2015 11:11 AM
Last Post: Only3
[.NET] by BerryPDec 22, 2014 03:56 PM 8 350 Dec 22, 2014 03:56 PM
Last Post: BerryP