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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:07:51+00:00 2026-05-15T08:07:51+00:00

Starting from this example: http://support.microsoft.com/kb/828736 I have tried to add a test function in

  • 0

Starting from this example: http://support.microsoft.com/kb/828736 I have tried to add a test function in my C# DLL which takes strings as parameters. My C# DLL code is as follows:

namespace CSharpEmailSender
{
   // Interface declaration.
   public interface ICalculator
   {
       int Add(int Number1, int Number2);
       int StringTest(string test1, string test2);
   };

// Interface implementation.
public class ManagedClass : ICalculator
{
    public int Add(int Number1, int Number2)
    {
        return Number1 + Number2;
    }

    public int StringTest(string test1, string test2)
    {
        if (test1 == "hello")
            return(1);

        if (test2 == "world")
            return(2);

        return(3);
    }
}

I then register this DLL using regasm. I use it in my C++ app like so:

using namespace CSharpEmailSender;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM.
HRESULT hr = CoInitialize(NULL);

// Create the interface pointer.
ICalculatorPtr pICalc(__uuidof(ManagedClass));

long lResult = 0;
long lResult2 = 0;

pICalc->Add(115, 110, &lResult);
wprintf(L"The result is %d", lResult);

pICalc->StringTest(L"hello", L"world", &lResult2);
wprintf(L"The result is %d", lResult2);

// Uninitialize COM.
CoUninitialize();

return 0;

}

After running this, lResult is correct (with value of 225), but lResult2 is zero. Any idea what I’m doing wrong?

  • 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-15T08:07:52+00:00Added an answer on May 15, 2026 at 8:07 am

    Without trying to compile this, perhaps the interop expects the string to be of BSTR type. Can you try the following?

    pICalc->StringTest(CComBSTR(L"hello"), CComBSTR(L"world"), &lResult2);
    

    OR

    pICalc->StringTest(::SysAllocString(L"hello"), ::SysAllocString(L"world"), &lResult2); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a simple TPH example from http://msdn.microsoft.com/en-us/library/dd793152.aspx . I have two
Given this example taken from http://php.net/manual/en/function.crypt.php crypt('rasmuslerdorf', '$2a$07$usesomesillystringforsalt$') Firstly: What is the length that
starting from this point: http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system I'm trying to create an application to save a
I am studying Backbone and the todo example apps from http://todomvc.com/ I have noticed
Starting from this official statement that all xyAndroid versions previous API 11 doesn't support
Starting from Android 3.2 I have this strange problem. It's very easy to reproduce:
Let's take these URLs as an example: http://www.youtube.com/watch?v=8GqqjVXhfMU&feature=youtube_gdata_player http://www.youtube.com/watch?v=8GqqjVXhfMU This PHP function will NOT
Starting an app here: http://developer.android.com/training/basics/firstapp/index.html Copying directly from the tutorial and it's full of
Could you provide example of JavaScript function for starting up application installed on your
Using code from this site this.screenshotPreview = function(){ /* CONFIG */ xOffset = 10;

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.