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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:55:29+00:00 2026-06-15T19:55:29+00:00

I have some trouble using a c dll in a c# application. The function

  • 0

I have some trouble using a c dll in a c# application. The function which gives me an error is defined in the header file of the dll like this:

int __stdcall DDC_CreateFilePropertyString (DDCFileHandle file, 
                                        const char *property,
                                        const char *value);

I added the following code in my class where I access the dll.

[DllImport("nilibddc.dll", CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
private static extern int DDC_CreateFilePropertyString(IntPtr file,
                         [MarshalAs(UnmanagedType.LPStr)]string property,
                         [MarshalAs(UnmanagedType.LPStr)]string value);

The Type DDCFileHandle is defined in the header file like this:

typedef struct _DDCFile DDCFile;
typedef DDCFile*    DDCFileHandle;

There is are no additional information about the _DDCFile struct in the header file (i don’t have any other files from the library im using).

Before I’m calling the function DDC_CreateFilePropertyString() I call the following function to create a file and get the file handle.

[DllImport("nilibddc.dll", CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Ansi]
private static extern int DDC_CreateFile(char[] filePath,
                          char[] fileType,
                          char[] name,
                          char[] description,
                          char[] title,
                          char[] author,
                          ref IntPtr file);

The definition in the header file looks like this.

int __stdcall DDC_CreateFile (const char *filePath,
                          const char *fileType,
                          const char *name,
                          const char *description,
                          const char *title,
                          const char *author,
                          DDCFileHandle *file);

Now always when i call the function DDC_CreateFilePropertyString it returns me an error telling me that i have some wrong parameters passed. What am i doing wrong? The library I’m using is the TDMS C API from National instruments.

Thanks for your help.

  • 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-06-15T19:55:30+00:00Added an answer on June 15, 2026 at 7:55 pm

    Your p/invokes are a little off. You need to use CallingConvention.Stdcall, which is the default. And for the const char* parameters you should simply declare them to be string at the C# end.

    The correct C# p/invoke for DDC_CreateFile is:

    [DllImport("nilibddc.dll", CharSet=CharSet.Ansi]
    private static extern int DDC_CreateFile(
        string filePath,
        string fileType,
        string name,
        string description,
        string title,
        string author,
        ref IntPtr file
    );
    

    And for DDC_CreateFilePropertyString you need this:

    [DllImport("nilibddc.dll", CharSet=CharSet.Ansi)]
    private static extern int DDC_CreateFilePropertyString(
        IntPtr file,
        string property,
        string value
    );
    

    If, after fixing your code, you still receive errors when calling these functions, then you are clearly using the library incorrectly. And that’s beyond the scope of this question. Consult the documentation, and/or seek support from the library vendor.

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

Sidebar

Related Questions

I have some trouble using decltype for member function pointers: #include <iostream> #include <type_traits>
I have some trouble reading from an ini file using boost program options. The
I have some trouble showing/hiding this menu on mouse enter. I'd like the menu
I'm having some trouble using constraints correctly. I have three tables, 'item', 'store' and
I have trouble using sed. I need to replace some lines in very deprecated
I have a ASP.NET MVC site using Membership Provider. I have trouble testing some
I have some trouble with jquery ui-events: In my application, there are some sliders.
I have some trouble achieving adequate real-time performance from my application and wondering if
i am using c++ and i have some trouble about pointers i know that
I'm having some trouble using sessions with php.. I think I have figured out

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.