Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have load an unmanaged dll from c# dot net. ITs signature is like below
This method returns the printer initialization string.
HRESULT WINAPI EndInit(
LPWSTR lpRbdFilename, LPSTR lpBuffer,
UINT uSize
) ;
Parameters
LpRbdFilename The file name of the RBD file. The string is Null-terminated. lpBuffer                
   A pointer to the buffer to receive the printer init string.
uSize               The maximum size of the buffer in TCHARs. The buffer length must include room 
for a terminating null character.

Return value
If the function succeeds, the return value is zero.
If the function fails, the return value is the error code.


What I have tried:

I have written the code like
[DllImport("tjp.dll", EntryPoint = "EndInit")]
public static extern string EndInit([MarshalAsAttribute(UnmanagedType.LPWStr)] string Rbd, char[] str, uint i);


and calling by sending by the following value by below code
var res = StartInit();
              
                if (res == 0)
            {

               
                    FileLogger.Info("Printer is connected.");
            }
               
                
                string path = "C:\\Users\\Iftekher Alam\\Desktop\\KBZ\\Emptly_Cheque_Printer\\noname.rbd";
               

            
                char[] buffer = new char[200000000];
            buffer[0] = 'H';
            buffer[1] = 'r';




            var loadEnd = EndInit(path, buffer, Convert.ToUInt32(buffer.Length));
                if (loadEnd == 0)
                {
                    FileLogger.Info("Document is printing...");
                }


EndInit
should return zero(0) int value if the method succeeded. But I got null value from the call.
Posted
Updated 23-Mar-21 7:38am

1 solution

C#
public static extern string EndInit([MarshalAsAttribute(UnmanagedType.LPWStr)] string Rbd, char[] str, uint i)

You have declared the function to return a string, but it returns an int according to your description. So what you saw as null, was actually zero, which is the success code.
 
Share this answer
 
Comments
Amir Hamza Kayes 23-Mar-21 13:48pm    
sorry to paste previous method here. later I made that return type as int. But after that it has also the same result
Richard MacCutchan 23-Mar-21 14:01pm    
Return value
If the function succeeds, the return value is zero.
If the function fails, the return value is the error code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900