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 210547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:00:55+00:00 2026-05-11T18:00:55+00:00

I’m creating a C api that hides some functionality in a DLL file. Since

  • 0

I’m creating a C api that hides some functionality in a DLL file.

Since everything is C++ on the inside most of the functions works against handles which maps directly to this pointers on the inside of the API.

To get a some degree of type safety for those handles I define them like this:

typedef struct MyType1* MyType1Handle;
typedef struct MyType2* MyType2Handle;

I don’t actually define MyType1 or MyType2 at any place since I only use them as pointers and do a type cast on the inside of the api to the actual pointer type.

My problem is that when using my library in a clr project in visual studio I get this warning: unresolved typeref token (token) for 'type'; image may not run.

http://msdn.microsoft.com/en-us/library/h8027ys9(VS.80).aspx

It’s no big deal since it works, but it looks unprofessional.

I don’t like using void*:

typedef void* MyType1Handle;
typedef void* MyType2Handle;

This makes it possible to call a function wanting a MyType1Handle with a MyType2Handle since they are actually the same type.

Another approach I don’t want to use is something like this

typedef int MyType1Handle;
typedef int MyType2Handle;

This would work fine as long as int’s and pointers have the same size, but that’s not always the case and it seems like there is no foolproof way of getting a platform specific pointer sized integer. It has the same type safety problems as the void* as well.

Another approach I tried was to do it like this:

struct MyType1{};
typedef struct MyType1* MyType1Handle;

This didn’t work in C since empty structs is invalid C code. I could of course extend my struct with a dummy member, but it seems like there should be a better way of doing this.

So my question boils down to:

How do you generally specify this kind of types in the most compatible way?

  • 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-11T18:00:55+00:00Added an answer on May 11, 2026 at 6:00 pm

    If you look at how Microsoft defines it’s winapi handles (winnt.h) it actually looks like this:

    struct HWND__ { int unused; }; typedef struct HWND__ *HWND
    

    in fact they have a macro for this:

    #define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name
    

    so.. this seems to be a common practice to do so.
    Unfortunately I can’t make another suggestion except this one, which you already
    mentioned, but I hope it helps you anyway.

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

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer .className rather than .class May 12, 2026 at 12:24 am
  • Editorial Team
    Editorial Team added an answer Yes. You cannot do that inside a table, but you… May 12, 2026 at 12:24 am
  • Editorial Team
    Editorial Team added an answer I'm pretty sure the above won't compile. DoSomething(j) is an… May 12, 2026 at 12:24 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.