Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling VB callback function (with strings) from VC++ worker thread

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am trying to call a VB callback function from my VC++ program. The VB callback looks like this:

Public Function PacketRetriever(ByVal src_mac As String)
Form1.Label1 = Right(src_mac, 1)
End Function

I originally tried sending back the string from VC++ as a char*, then as a LPSTR, and finally found advice on MS TechNet that said I should send back a BSTR.

I still get an Access Violation, the assembly source being:
660243FF push dword ptr [edx-4]
(edx = 0x14)

Can anyone help with this? I am attempting to write a firewall like ZoneAlarm that will protect my entire network from outside IPs sending SYN packets. The offending code is in a worker thread that receives packets from the NIC, and is as follows:

void dispatcher_handler(u_char *temp1, const struct pcap_pkthdr *header, const u_char *pkt_data)
{
myPacket thePacket;
static BSTR src_mac_address;
static char dest_mac_address;
src_mac_address = (BSTR)malloc(21);
vswprintf(src_mac_address,L"100.200.300.400","%s");
Beep(500,1);
BSTR test = SysAllocString(src_mac_address);
PacketCallback( test );
}

I'm probably doing all kinds of stuff wrong because I haven't dealt with BSTR types before. I'm also faking the IP currently (instead of reading it from the packet).
Any help would be GREATLY appreciated, and will get an honorable mention in the final product (and a free copy!)

Regards,
Chris
cregister@yahoo.com
 
char is single byte array, but bstr (BASIC string) is double byte char. Also in C++ BSTR is quite the same.
for example you can
char* x = "hello";
BSTR* y = L"hello";//pay attention on L
to pass y as an argument you should pass SysAllocString(y) instead of y (in my opinion you're using COM). John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top