Solved

Pass string variable from ASP to C++ DLL Chop

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

948 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

22 Experts available now in Live!

Get 1:1 Help Now