Solved

Pass string variable from ASP to C++ DLL Chop

Posted on 2004-09-03
3
231 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
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 125 total points
Comment Utility
>>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
Comment Utility
Oh, BTW, you'll have to

#include <comdef.h>

for the above.
0
 

Author Comment

by:sebou23
Comment Utility
_bstr_t bstr(Username); working good.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now