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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
P

poda

@poda
About
Posts
46
Topics
14
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How to access multiple controls thread safe in Windows Forms
    P poda

    Would you please kindly refer me some links.

    C# winforms tutorial question announcement

  • How to access multiple controls thread safe in Windows Forms
    P poda

    Thanks for your replies Luc Pattyn. Here you only use dataGridView1.Invoke, but update other controls also.Is that ok?

    C# winforms tutorial question announcement

  • How to access multiple controls thread safe in Windows Forms
    P poda

    In article, you suggest to use Control and the property as generic parameter. But Control is the base class.The common property is only Text for all controls. But in case of specific properties of a control,how can use generic method. Suppose DataGridView.Rows[2].Cells[3].Value-how can use Control? Because Control.Rows does not exists. So if I need to update or access 3 controls 2 properties, then have to write 6 delegates and 6 functions to do the job?

    C# winforms tutorial question announcement

  • How to access multiple controls thread safe in Windows Forms
    P poda

    Many examples explains thread safe access over a single control,like updating a text of a button or label etc.,How to change properties of multiple controls of a Form in thread safe manner.

    private Thread CheckStatusThread = null;
    public delegate void CheckStatusDelegate(int Count);
    public CheckStatusDelegate CheckStatusHandler;

    public Form1()
    {
    InitializeComponent();
    CheckStatusThread = new Thread(new ThreadStart(CheckStatusThreadFunc));
    CheckStatusHandler = new CheckStatusDelegate(CheckPowerStatus);
    }
    private void Form1_Load(object sender, EventArgs e)
    {
    CheckStatusThread.Start();
    }
    public void CheckStatusThreadFunc()
    {
    int Cnt = 1;
    while (true)
    {
    this.Invoke(CheckStatusHandler,new object []{Cnt});//executed in Form1's own thread(?)
    Cnt++;
    Thread.Sleep(500);
    }
    }

    public void CheckPowerStatus(int Count)
    {
    int Cnt=Count;

    //Update 3 controls properties
    StatusBarLabel1.Text = "Checking PowerStatus " + Cnt;
    dataGridView1.Rows[2].Cells[4].Value = Cnt;
    label1.Text = Convert.ToString("Cnt "+Cnt);
    }

    The CheckPowerStatus function change properties of 3 controls in Form1. Do I need to use 3 delegates to update each control on 3 different functions. Or the above code is thread safe?

    C# winforms tutorial question announcement

  • Marshalling array of struct
    P poda

    Finally I found a solution for my problem. Pointer increment can be done by ToInt32() function of IntPtr and adding the Offset. Here Offset is the size of the element in the array.

    IntPtr pPointer;
    module_Str AModule;
    DeviceSize = Marshal.SizeOf(typeof(module_Str));
    pPointer=Marshal.AllocHGlobal(DeviceSize*4); //since the passed struct array size is 4
    GetModules(ref NumOfTestHead, pPointer, ref SW_Version); //call to DLL function

    //Now the pPointer hold a long array of bytes which has the values of array of 4 module_Str
    int Offset=0;
    for (i = 0; i<4; i++)
    {
    IntPtr IncrPtr = new IntPtr(pPointer.ToInt32() + Offset);// base address + offset
    AModule=(module_Str)Marshal.PtrToStructure(IncrPtr, typeof(module_Str));
    Offset = Offset + Marshal.SizeOf(typeof(module_Str)); //increment the pointer by size of module_str
    for (j = 0; j <13; j++)//the inner struct array size is 13
    {
    ListBox.Items.Add("DeviceID : " + AModule.module[j].deviceId);
    ListBox.Items.Add("Version : " + AModule.module[j].version);
    ListBox.Items.Add("Valid : " + AModule.module[j].valid);
    ListBox.Items.Add("FlashData: " + AModule.module[j].flashData);
    ListBox.Items.Add("TestHead : " + AModule.testHdId);
    ListBox.Items.Add("");
    }
    }
    //Finally free the allocated memory
    Marshal.FreeHGlobal(pPointer);

    C# csharp data-structures help tutorial announcement

  • Marshalling array of struct
    P poda

    I cannot change the struct in DLL,because it is used by many application. I tried using Marshal.PtrToStructure. But do not know how to increment the pointer. Now the value is correct for the first array element. Can you help in incrementing the pointer that points to the array of structures.

    IntPtr pPointer;
    module_Str AModule;
    DeviceSize = Marshal.SizeOf(typeof(module_Str));
    pPointer=Marshal.AllocHGlobal(DeviceSize*4);//since I pass array of 4 module_Str
    GetModules(ref NumOfTestHead, pPointer, ref SW_Version);

    AModule=(module_Str)Marshal.PtrToStructure(pPointer, typeof(module_Str));

    DeviceId=AModule.module[0].deviceID//is correct

    But how to increment the pointer to get each array element of structure, ie.AModule[0],AModule[1] and so on..

    C# csharp data-structures help tutorial announcement

  • Marshalling array of struct
    P poda

    It is a nice tool man. But unfortunately it does not work for my problem.

    C# csharp data-structures help tutorial announcement

  • Marshalling array of struct
    P poda

    When I use out or ref keyword,I get System.ExecutionEngineException error. If not specified,it compiles and run smooth, but no change in the values of struct. I have modified the C# struct accordingly by the P/Invoke Interop Assistant result,but no gain. What to do?.

    C# csharp data-structures help tutorial announcement

  • Marshalling array of struct
    P poda

    The size of structure sent is always 4.It is fixed. Only the ref param receives correct value from the function. But ModuleDef[0].module[0].deviceId do not get correct value. Does anyone know how to achieve this. Thanks Luc Pattyn for your reply.

    modified on Friday, September 24, 2010 3:30 AM

    C# csharp data-structures help tutorial announcement

  • Marshalling array of struct
    P poda

    I want to pass a struct which has a array of struct to a unmanaged code(a C DLL) and get the struct filled by the function in the DLL.Kindly help me to do this. In C DLL

    #define DLL_EXPORT extern "C" __declspec(dllexport)

    typedef struct device_Struct
    {
    int valid;
    int deviceId;
    int version;
    char flashData[100];
    } device_def;

    typedef struct module_Struct
    {
    device_def module[13];
    int testHdId;
    }module_def;

    DLL_EXPORT int _stdcall GetModules(int *TestHead,module_def *Module_Def)
    {
    *TestHead=2;

    (Module_Def+0)->module[0].valid=1;//Module_Def is array of module_def
    (Module_Def+0)->module[0].deviceId=5;
    (Module_Def+0)->module[0].version=2;
    strcpy((Module_Def+0)->module[0].flashData,"FlashData");
    Module_Def[0].testHdId=3;
    return 1;
    }

    In C# code

    [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]
    public struct device_Str
    {
    public int valid;
    public int deviceId;
    public int version;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
    public string flashData;
    };
    [StructLayout(LayoutKind.Sequential)]
    public struct module_Str
    {
    [MarshalAs(UnmanagedType.ByValArray,SizeConst=13)]
    public device_Str[] module;
    public int testHdId;
    };

    [DllImport("BCB_DLL.dll")]
    public static extern int GetModules(ref int TestHead, module_Str[] Module_Def);

    //Main call
    int i,j,NumOfTestHead=0,DeviceID;
    module_Str[] ModuleDef = new module_Str[4];

    for (i = 0; i < 4; i++)
    {
    ModuleDef[i] = new module_Str();
    ModuleDef[i].module = new device_Str[13];
    for (j = 0; j < 13; j++)
    {
    ModuleDef[i].module[j] = new device_Str();
    }
    }
    GetModules(ref NumOfTestHead, ModuleDef);
    DeviceID=ModuleDef[0].module[0].deviceId;//Do not get the correct value

    I know I have to do Marshalling. Help me how to do that.

    C# csharp data-structures help tutorial announcement

  • Marshaling the structure array member of Structure in C#
    P poda

    Hai Vini Deep, My need is same as your problem. Please reply if you have solved it. Thanks friend.

    C# help question csharp data-structures

  • Getting the bitmap in and out of a CGIPLUS Image class
    P poda

    GdiplusShutdown must be called out of scope of the Bitmap object. The Unhandled exception arise because the GdiplusShutdown function is called before the Bitmap object is destructed.So define Bitmap object within { }. short jpgread (image&I, char*filename) { // int CurY; GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); { // converts ANSI string to WCHAR string CA2W wcharfilename(filename); Bitmap MyBitmap(wcharfilename); }//MyBitmap goes out of scope here GdiplusShutdown(gdiplusToken); return 1; }

    C / C++ / MFC graphics c++ question delphi winforms

  • Deleting a file used by another process.
    P poda

    Before deleting the file,try using SetFileAttributes(FileName,FILE_SHARE_DELETE);

    C / C++ / MFC com linux

  • Deleting a file used by another process.
    P poda

    I am also facing a situation same as you,need to delete a file which is locked by another process. But still do not know the solution. For your reference,he is the code to do this,but this application is also not very successful on deleting. http://sourceforge.net/project/showfiles.php?group_id=151239[^] In my case I need to delete the locked file,and again create it using a Linker(ILINK32.exe) to produce a DLL. Even when using Unlocker to delete the file,it is not possible to create the same file.The linker gives me error like "Cannot release virtual memory at addr xxxx for xxxxx bytes".

    C / C++ / MFC com linux

  • How to Unlock a file
    P poda

    Ofcourse,it will release the file. But I will use the linker to create DLL as a separate process for which the .tds file has to be deleted when the IDE is open. I need to know to how to release or unlock a file which is holding by a application. Thank you

    C / C++ / MFC help algorithms tools tutorial question

  • How to Unlock a file
    P poda

    Yes I want to do it programatically. When we compile and link a project,the compiler will generate many files(like obj,map,ils,tds etc). One of them is .tds file. But this file is 'hold' by the IDE of Borland C++. How to release this 'lock' so that it can be deleted.

    C / C++ / MFC help algorithms tools tutorial question

  • How to Unlock a file
    P poda

    Not OS locked. The file is "*.tds" file generated by Borland C++ (bcc32.exe) compiler.

    C / C++ / MFC help algorithms tools tutorial question

  • How to Unlock a file
    P poda

    Dear Friends, I want to delete a file which is used by other application. When I try to delete that file,it shows error as "Cannot delete file: It is being used by another person or Program.Close any programs that might be using the file and try again." On searching Google, some utility programs like "Unlocker" does this. But I am in need of the code just only to unlock the file and delete it. Could anyone help me out please? Thanks

    C / C++ / MFC help algorithms tools tutorial question

  • WIN32 API to find Mouse Button State
    P poda

    Thanks for your replies friends. I used like SHORT LButtonDown; LButtonDown=GetKeyState(VK_LBUTTON); if(LButtonDown & 0x8000) { ...code here } It works.Thanks a lot.

    C / C++ / MFC json tutorial

  • WIN32 API to find Mouse Button State
    P poda

    Dear Friends, How to know whether the mouse button is Down even if it moving.The WM_LBUTTONDOWN message is fired only for the first time left button is pressed. But how to know whether it is pressed all the time though it may be moving.

    C / C++ / MFC json tutorial
  • Login

  • Don't have an account? Register

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