Solved

Pass string variable from ASP to C++ DLL Chop

Posted on 2004-09-03
3
271 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 125 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

617 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