Solved

Pass string variable from ASP to C++ DLL Chop

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 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.
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.

751 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