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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:31:19+00:00 2026-05-28T20:31:19+00:00

I’m trying to use a method from a C++ DLL in a C# project,

  • 0

I’m trying to use a method from a C++ DLL in a C# project, but I’m, having problems calling it correctly.
The method is this:

As said in the SDK manual


DWORD WINAPI PrtRead (HANDLE hPrt, DWORD dwTimeout, DWORD *pdwType, LPDWORD pdwParArray, LPDWORD pdwArraySize, LPBYTE pbReadData, LPDWORD pdwReadDataLen)

As really defined on code

extern "C" __declspec(dllimport) DWORD PrtRead (HANDLE hPRT, DWORD dwTimeout, DWORD *pdwType, LPDWORD pdwParArray, LPDWORD pdwArraySize,LPBYTE  pbReadData, LPDWORD pdwReadDataLen);

and in the SDK C++ sample they call it like this:

DWORD       dwPar[2];
pdwParArray = &dwPar[0];
dwPar[0] = 0;
dwPar[1] = 0;

DWORD dwRet = PrtRead(hPrinter, dwCurrentTimeout, &dwType, pdwParArray, &dwArraySize, NULL, &dwReadDataLen);

My problem is getting the value LPDWORD pdwParArray.

The DLL always returns one of the following values in position [0]: 1, 2 or 20 and in postion [1]: 1, 2 or 4, but I’m unbale to make it do this.

I’ve tryed defining the import like this:

[DllImport("HPRDH.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern ulong PrtRead(IntPtr hPrt, ulong dwTimeout, ref ulong pdwType, XXXXXXXXX , ref ulong pdwArraySize, ref byte[] pbReadData, ref ulong pdwReadDataLen);

and varied XXXXXXXXX like this


Method definition:

out ulong[] pdwParArray

Variable Initialization:

ulong[] pdwParArray;

Method returns:

pdwParArray = null

Method definition:

ref ulong[] pdwParArray

Variable Initialization:

ulong[] pdwParArray = new ulong[2];
pdwParArray[0] = 0;
pdwParArray[1] = 0;

Method returns:
pdwParArray[0] = 0;
pdwParArray[1] = Out of bounds array index;


Method definition:
out ulong pdwParArray

Variable Initialization:
ulong[] pdwParArray = new ulong[2];

Method returns:
pdwParArray[0] = 0;
pdwParArray[1] = 0;


Method definition:
ref ulong pdwParArray

Variable Initialization:
ulong[] pdwParArray = new ulong[2];

Method returns:
pdwParArray[0] = 0;
pdwParArray[1] = 0;


How should I define the LPDWORD pdwParArray in my C# import, how to initialize it and call it?

Thanks in advance

_
_
_
_

EDIT:
@TheMathemagician

Tried the following with these results:

Definition:

[MarshalAs(UnManagedType.LPArray)] ulong[] pdwParArray

Result:

pdwParArray[0] = 0;

pdwParArray[1] = 0;


Definition:

[MarshalAs(UnmanagedType.LPArray)] out ulong[] pdwParArray

Result:

pdwParArray[0] = null;

pdwParArray[1] = null;


Definition:

[MarshalAs(UnmanagedType.LPArray)] ulong pdwParArray

Result:

Cannot marshal ‘parameter #4’: Invalid managed/unmanaged type combination (Int64/UInt64 must be paired with I8 or U8).


Definition:

[MarshalAs(UnmaDefinition:nagedType.LPArray)] out ulong pdwParArray

Result:

Cannot marshal ‘parameter #4’: Invalid managed/unmanaged type combination (Int64/UInt64 must be paired with I8 or U8).

  • 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-28T20:31:20+00:00Added an answer on May 28, 2026 at 8:31 pm

    As almost all the answers where about the same thing, and even so It wasn’t working, I decided to look even deeper into the SDK sample, and realized I needed to call PrtRead(…) a second time to get the correct values.

    I ended up by using:

    [DllImport("HPRDH.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern UInt32 PrtRead(IntPtr hPrt, UInt32 dwTimeout, ref UInt32 pdwType, out UInt32 pdwParArray, ref UInt32 pdwArraySize, ref byte[] pbReadData, ref UInt32 pdwReadDataLen);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, 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.