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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:57:07+00:00 2026-05-10T17:57:07+00:00

I need to call an external dll from c#. This is the header definition:

  • 0

I need to call an external dll from c#. This is the header definition:

enum WatchMode {     WATCH_MODE_SYSTEM = 0,              WATCH_MODE_APPLICATION  = 1 };    LONG ADS_API WDT_GetMode ( LONG i_hHandle, WatchMode * o_pWatchMode ); 

I’ve added the enum and the call in C#:

public enum WatchMode {     WATCH_MODE_SYSTEM = 0,     WATCH_MODE_APPLICATION = 1        } [DllImport('AdsWatchdog.dll')] internal static extern long WDT_GetMode(long hHandle, ref WatchMode watchmode); 

This generates an AccessViolationException. I know the dll is ‘working’ because I’ve also added a call to GetHandle which returns the hHandle mentioned above. I’ve tried to change the param to an int (ref int watchmode) but get the same error. Doesn anyone know how I can PInvoke the above call?

  • 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. 2026-05-10T17:57:08+00:00Added an answer on May 10, 2026 at 5:57 pm

    You’re running into a parameter size problem difference between C# and C++. In the C++/windows world LONG is a 4 byte signed integer. In the C# world long is a 8 byte signed integer. You should change your C# signature to take an int.

    ffpf is wrong in saying that you should use an IntPtr here. It will fix this particular problem on a 32 bit machine since an IntPtr will marshal as a int. If you run this on a 64 bit machine it will marshal as a 8 byte signed integer again and will crash.

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

Sidebar

Related Questions

In external (Delphi-created) DLL I've got the following function that I need to call
I need to call a wrapped function from a C++ DLL with the following
Hi i need to call a external EXE (same running exe )from a C++
I need to call a method in an external assembly from a scripting functoid
I need to call a const function from a non-const object. See example struct
I have a VB6 COM component which I need to call from my .Net
I have a Delphi DLL that I did not write, but need to call
I need to call javascript function from Flash 4 based web application. When I
I need to call into a Win32 API to get a series of strings,
I need to call a method that accepts a stream argument. The method loads

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.