Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Pass string variable from ASP to C++ DLL Chop

Posted on 2004-09-03
3
Medium Priority
?
272 Views
Last Modified: 2010-04-01
I try to pass a string variable from ASP to VC++ DLL.
When i send "abc" from ASP to  BSTR Username in VC++ DLL, he only print "a"
How can i pass complete string to VC++ DLL?

ASP:
Set Com = Server.CreateObject("NETCLUB.Com")
ComResult=Com.Add(123,"abc")
Set Com = Nothing

VC++ DLL
STDMETHODIMP CCom::Add(LONG UserId, BSTR Username, LONG *Result)
{
      AFX_MANAGE_STATE(AfxGetStaticModuleState());

      Message record;
      memset(record.type,  0, sizeof(record.type));
      memset(&record.user, 0, sizeof(record.user));
      memset(&record, 0, sizeof(Message));

      record.user.UserId = UserId;
      strncpy(record.user.Username, (const char *)Username, 22);
      record.user.Username[22]= '\0';

      *Result=StreamClient("whamzeh30", SERVERPORT, record, "");

      WSACleanup();
      return S_OK;
}
0
Comment
Question by:sebou23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 11974051
>>strncpy(record.user.Username, (const char *)Username, 22);

You are getting a BSTR*, you cannot just 'strncpy()' that into a char buffer. Use

__bstr_t bstr(Username);

strncpy(record.user.Username, (const char *)bstr, 22);// invoke 'operator char*( )' to convert to 'char*
0
 
LVL 86

Expert Comment

by:jkr
ID: 11974107
Oh, BTW, you'll have to

#include <comdef.h>

for the above.
0
 

Author Comment

by:sebou23
ID: 11975035
_bstr_t bstr(Username); working good.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question