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

  • SEARCH
  • Home
  • 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 6736085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:05:19+00:00 2026-05-26T11:05:19+00:00

I am trying to port C++ code to C#. The code is meant to

  • 0

I am trying to port C++ code to C#. The code is meant to register a window class using RegisterClassEx.

The C++ code has an object WNDCLASSEX wcex. Object wcex has a property

wcex.cbSize = sizeof(WNDCLASSEX);

In C#, I have defined the structure as

    [StructLayout(LayoutKind.Sequential)]
    public struct WNDCLASSEX
    {
        public uint cbSize;
        public uint style;
        [MarshalAs(UnmanagedType.FunctionPtr)]
        public PlatformInvokeGDI32.WNDPROC lpfnWndProc;
        public int cbClsExtra;
        public int cbWndExtra;
        public IntPtr hInstance;
        public IntPtr hIcon;
        public IntPtr hCursor;
        public IntPtr hbrBackground;
        public string lpszMenuName;
        public string lpszClassName;
        public IntPtr hIconSm;
    }

I have tried to get the size using

wcex.cbSize = (uint)sizeof(WNDCLASSEX);

The function containing this stament is declared as

unsafe private void

I hoped the unsafe would make the statment work. However, I get this error in the IDE:

Cannot take the address of, get the size of, or declare a pointer to a managed type ('CaptureScreen.PlatformInvokeGDI32.WNDCLASSEX')

Can I make the structure into an unmanaged structure? If so, how?
Is there a way to use sizeof without making the structure unmanaged?
Is there a .NET version of sizeof that would work?

  • 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-26T11:05:20+00:00Added an answer on May 26, 2026 at 11:05 am

    Use Marshal.SizeOf instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to port code over to compile using Microchip's C18 compiler for a
I'm trying to port some code into .net which has a load of #define'd
I am trying to port some c++ code to my android application using NDK.
I am trying to port some code using VC++'s try-except statement to MinGW: bool
We are trying to port our code from HPX to AIX but getting core
I am trying to port the code below to mootools 1.1 code but am
I'm trying to port some Windows code to Linux, ideally through platform-independent libraries (eg
I'm trying to port some of my c++ code into c. I have the
I am trying to port this algorithm to clojure. My code is (defn calc-iterations
I'm trying to set the port on a cookie in ASP.NET (code below), but

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.