Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
A

amirreza_nl

@amirreza_nl
About
Posts
9
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • SerialPort
    A amirreza_nl

    Thanks a lot. Yes I must add carriage return to the end of the string (+"\r").

    .NET (Core and Framework) csharp

  • SerialPort
    A amirreza_nl

    Hi, I want to do simple thing but I can't and I'm confused. I want to send a simple at command to my modem. like atdt8889653 SerialPort s = new SerialPort("com3", 2400, Parity.None, 8, StopBits.One); try{ s.Open(); s.Write("atdt8889653"); ... } catch { ... } but it seems it doesn't work because my modem doesn't call; my apps is win form I see this code http://www.dreamincode.net/forums/showtopic35775.htm[^] but it doesn't work. (I can connect to my modem via hyper terminal and type at commands and get correct responces)

    .NET (Core and Framework) csharp

  • SetWindowsHookEx (keylogger app) - Memory Access Violation
    A amirreza_nl

    Hi, I wrote a piece of code to monitor keyword activities (just for fun and testing this api func) I want to know what is wrong? sometime I get this error: {"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."} Stack trace: " at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)\r\n at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.Run()\r\n at hook.Program.Main() in C:\\Documents and Settings\\Nazila\\My Documents\\Visual Studio 2005\\Projects\\hook\\hook\\Program.cs:line 19" my code is : public class KeyPosition { static public Int16 WM_KEYDOWN = 0x0100; static public Int16 WM_KEYUP = 0x0101; static public Int16 WM_SYSKEYDOWN = 0x0104; static public Int16 WM_SYSKEYUP = 0x0105; } delegate int HookProc(int code, IntPtr wParam, ref keyboardHookStruct lParam); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] static extern IntPtr SetWindowsHookEx(HookType hook, HookProc callback, IntPtr hMod, uint dwThreadId); [DllImport("user32.dll", CharSet = CharSet.Auto,CallingConvention = CallingConvention.StdCall)] public static extern bool UnhookWindowsHookEx(int idHook); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] static extern int CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, ref keyboardHookStruct lParam); [DllImport("kernel32.dll")] static extern IntPtr LoadLibrary(string lpFileName); public enum HookType : int { WH_JOURNALRECORD = 0, WH_JOURNALPLAYBACK = 1, WH_KEYBOARD = 2, WH_GETMESSAGE = 3, WH_CALLWNDPROC = 4, WH_CBT = 5, WH_SYSMSGFILTER = 6, WH_MOUSE = 7, WH_HARDWARE = 8, WH_DEBUG = 9, WH_SHELL = 10, WH_FOREGROUNDIDLE = 11, WH_CALLWNDPROCRET = 12, WH_KEYBOARD_LL = 13, WH_MOUSE_LL = 14 } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto,Pack=1)] public struct keyboardHookStruct { public int vkCode; publ

    C# question csharp visual-studio data-structures testing

  • convert structure to IntPtr
    A amirreza_nl

    oh, I think I find the bug in my code! I write: [StructLayout(LayoutKind.Sequential, Pack = 1)] but I must write: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)] instead. I use unicode charset for my all methode definitions. But I wonder why this makes a problem! we have two types of pidl!? on for ansi one for unicode!? why? in pidl address we have string!??

    C# help

  • convert structure to IntPtr
    A amirreza_nl

    Hi, first of all, thanks for ur reply. I think SHGetFileInfo doesn't work well. because the first call's return value is ok. but SHGetFileInfo's return value sometimes is not ok. I run the code 2 or 3 times then it works well and show control panel's (or something else) attributes correctly! I don't know why! SHGetPathFromIDList doesn't work at all with something like control panel (I think). we can use it when pidl is controled by file system(file or folder that is stored physically in a hard disk). so I can not use it for my app. typedef struct _SHITEMID { USHORT cb; BYTE abID[1]; } SHITEMID; I wrote this in C#: [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct SHITEMID { public UInt16 cb; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]public SByte[] abID; } then typedef struct _ITEMIDLIST { SHITEMID mkid; } ITEMIDLIST; in C#: [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct ITEMIDLIST { public SHITEMID mkid; }

    C# help

  • convert structure to IntPtr
    A amirreza_nl

    thanks, I see the code but I can't find out why my code doesn't work properly. my code is like the code in the page that you mention. (the caller is not presented in the page just callee is presented)

    modified on Friday, March 7, 2008 5:01 AM

    C# help

  • convert structure to IntPtr
    A amirreza_nl

    No, It doesn't help. because it assumes just file system paths not pidl!. you can not convert every pidl to string.

    C# help

  • convert structure to IntPtr
    A amirreza_nl

    Wow! it sometimes works ! a few times it is failed. I can not find out why! plz help!

    C# help

  • convert structure to IntPtr
    A amirreza_nl

    Hi, I want to use SHGetFileInfo from shell32.dll u can pass string or pidl(ITEMIDLIST structure) for first param the problem is: u can't convert string (file path) to pidl or vice versa. so I use IntPtr for first param. but the problem is I can't convert pidl to IntPtr. (the problem is the code below doesn't work I can't find out why) public class FileFolder { [DllImport("Shell32.dll", CharSet = CharSet.Unicode)] public static extern UInt32 SHGetFileInfo(IntPtr pszPath, UInt32 dwFileAttributes, ref SHFILEINFO psfi, UInt32 cbFileInfo, UInt32 uFlags); [DllImport("Shell32.dll", CharSet = CharSet.Unicode)] public static extern Int32 SHGetSpecialFolderLocation(IntPtr hwndOwner, int nFolder, ref ITEMIDLIST ppidl); [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct SHITEMID { public UInt16 cb; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]public SByte[] abID; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct ITEMIDLIST { public SHITEMID mkid; } } uint flag = FileFolder.C_GetFileInfoFlagt.SHGFI_PIDL| FileFolder.C_GetFileInfoFlagt.SHGFI_ICON | FileFolder.C_GetFileInfoFlagt.SHGFI_SHELLICONSIZE | FileFolder.C_GetFileInfoFlagt.SHGFI_ATTRIBUTES | FileFolder.C_GetFileInfoFlagt.SHGFI_TYPENAME; FileFolder.ITEMIDLIST pidl = new FileFolder.ITEMIDLIST(); if (FileFolder.SHGetSpecialFolderLocation(IntPtr.Zero, (int)0x0003, ref pidl) == 0) { MessageBox.Show("true"); } IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(pidl)); Marshal.StructureToPtr(pidl, pnt, true); if (FileFolder.SHGetFileInfo(pnt, 256, ref info, (uint)Marshal.SizeOf(info), flag) > 0) { MessageBox.Show("Successfull"); }

    C# help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups