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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:44:46+00:00 2026-05-23T07:44:46+00:00

How to correctly P/Invoke this function? const char * GetReplyTo(const char * pszInText, char

  • 0

How to correctly P/Invoke this function?

const char * GetReplyTo(const char * pszInText, char * pszOutText, int len)

I’ve tried to do it this way and got access violation exception:

[DllImport("SmartBot.dll", EntryPoint = "GetReplyTo")]
public static extern IntPtr GetReplyTo([In] [MarshalAs(UnmanagedType.LPStr)] string pszInText, IntPtr pszOutText, int len);

// somewhere below:
IntPtr pbuf = GCHandle.Alloc(new byte[1000], GCHandleType.Pinned).AddrOfPinnedObject();
GetReplyTo("hi", pbuf, 2);

UPDATE
Here is pascal header for this file:

 {***************************************************************************
 * SmartBot Engine - Boltun source code,
 * SmartBot Engine Dynamic Link Library
 *
 * Copyright (c) 2003 ProVirus,
 * Created Alexander Kiselev Voronezh, Russia
 ***************************************************************************
 SmartBot.pas : Header Pascal for SmartBot Engine.
 }

unit SmartBot;

interface

{
function GetReplyTo(const InText: PChar; OutText: PChar; Len: integer): PChar;stdcall;export;
function LoadMind(MindFile: PChar): integer;stdcall;export;
function SaveMind(MindFile: PChar): integer;stdcall;export;
}
function GetReplyTo(const InText: PChar; OutText: PChar; Len: integer): PChar;stdcall;external 'smartbot.dll' name 'GetReplyTo';
function LoadMind(MindFile: PChar): integer;stdcall;external 'smartbot.dll' name 'LoadMind';
function SaveMind(MindFile: PChar): integer;stdcall;external 'smartbot.dll' name 'SaveMind';

implementation
end.

UPDATE 2 It works. Looks like I messed up with initialization function. It returns 1 on success and 0 on fail. Weird.

  • 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-23T07:44:46+00:00Added an answer on May 23, 2026 at 7:44 am

    You probably don’t want an IntPtr here. You’re making way too much work for yourself. For an output string parameter, you should use StringBuilder. You’ll probably need to specify CharSet on your P/Invoke declaration, since the function appears to use one byte per character.

    [DllImport("SmartBot.dll", CharSet = CharSet.Ansi)]
    public static extern string GetReplyTo(string pszInText,
        StringBuilder pszOutText, int len);
    
    var stringBuilder = new StringBuilder(1000);
    GetReplyTo("hi", stringBuilder, stringBuilder.Capacity);
    

    Also make sure you’re specifying the right calling convention (the CallingConvention property on the DllImport attribute).

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

Sidebar

Related Questions

This code works correctly to make a web service call: int numberOfGuests = Convert.ToInt32(search.Guest);
Say I have this function: int func2() { printf(func2\n); return 0; } Now I
Edit--@Uri correctly pointed out that this was an abuse of annotations; trying to actually
If I understand this correctly: Current CPU developing companies like AMD and Intel have
I have a function GetAlertData() that returns a Datatable. I invoke it as: var
I'm looking for a way to make an NSInvocation invoke a specific IMP .
From various sources on teh interwebs I've gleaned this following function: public static Nullable<T>
I have this function: function start-sqlsnap { add-pssnapin SqlServerCmdletSnapin100 } Regardless of the method
If I understand correctly, ClickOnce only checks for prerequisites with the first install of
I cannot correctly position the div form in my layout. By looking at my

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.