Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 370741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:02:50+00:00 2026-05-12T14:02:50+00:00

I am trying to PInvoke UpdateProcThreadAttribute() on Windows 7 but my attempts just keep

  • 0

I am trying to PInvoke UpdateProcThreadAttribute() on Windows 7 but my attempts just keep returning FALSE with a Last Win32 Error of 50.

Function declaration (from MSDN)

BOOL WINAPI UpdateProcThreadAttribute(
  __inout    LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList,
  __in       DWORD dwFlags,
  __in       DWORD_PTR Attribute,
  __in       PVOID lpValue,
  __in       SIZE_T cbSize,
  __out_opt  PVOID lpPreviousValue,
  __in_opt   PSIZE_T lpReturnSize
);

Here is my attempt at the PInvoke signature:

[DllImport("kernel32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
public static extern bool UpdateProcThreadAttribute
(
            IntPtr lpAttributeList,
            UInt32 dwFlags,
            ref UInt32 Attribute,
            ref IntPtr lpValue,
            ref IntPtr cbSize,
            IntPtr lpPreviousValue,
            IntPtr lpReturnSize
);

Is this declaration sensible? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:02:51+00:00Added an answer on May 12, 2026 at 2:02 pm

    You have a few problems with your declaration but the one that is giving you the not supported error is the Attribute parameter. A DWORD_PTR is not a pointer but rather a pointer sized unsigned integer so rather than ref uint it should be an IntPtr.

    The declaration I would use is:

        [DllImport("kernel32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool UpdateProcThreadAttribute(
            IntPtr lpAttributeList, uint dwFlags, IntPtr Attribute,
            IntPtr lpValue, IntPtr cbSize, IntPtr lpPreviousValue, 
            IntPtr lpReturnSize);
    

    EDIT:

    I tried to do this as a comment but it doesn’t take to code very well.

    For a process handle you need an IntPtr to hold the handle. So you would need something like:

    IntPtr hProcess //previously retrieved.
    IntPtr lpAttributeList //previously allocated using InitializeProcThreadAttributeList and Marshal.AllocHGlobal.
    
    const int PROC_THREAD_ATTRIBUTE_PARENT_PROCESS = 0x00020000;
    IntPtr lpValue = Marshal.AllocHGlobal(IntPtr.Size); 
    Marshal.WriteIntPtr(lpValue, hProcess);
    if(UpdateProcThreadAttribute(lpAttributeList, 0, (IntPtr)PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, lpValue, (IntPtr)IntPtr.Size, IntPtr.Zero, IntPtr.Zero))
    {
        //do something
    }
    
    //Free lpValue only after the lpAttributeList is deleted.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the function PathCanonicalize using DllImport (PInvoke) on a 64
Possible Duplicate: A call to PInvoke function '[…]' has unbalanced the stack I'm trying
I'm trying to pinvoke a C function from IronPython 2.6 on Ubuntu 10.10. I've
I'm trying to PInvoke into this C++ library function: int Initialize(Callback* callback); struct Callback
I am trying to use some pinvoke code to call a C function. The
I am trying to use pInvoke, but on both the emulator and on the
I'm trying to write a pinvoke for the ITaskTrigger::GetTriggerString method (defined at http://msdn.microsoft.com/en-us/library/windows/desktop/aa381866(v=vs.85).aspx ).
Trying to copy the msdn refernce here doesn't work and gives an error I
I am trying to PInvoke CreateDesktop in a way that passes the flag to
I am using C# in Mono and I'm trying to use pinvoke to call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.