|
DavidCrow you are a true *.
|
|
|
|
|
Hi,
I have a C++ DLL question. I want to have two functions as follows in a DLL.
namespace View
{
long _stdcall MakeWindow();
long _stdcall RegisterClass();
}
Is it possible to use it in this form from VB. So, can I call these functions in VB ...something like View::MakeWindow(). My knowledge of VB and C++ for that matter is very basic and any help would be appreciated.
Also, I had another funny experience. I cannot export a void function. I know I am missing something and being really stupid. If I have a C++ function like:
void _stdcall someFunc()
{}
and I declare it in VB as:
Declare Function someFunc Lib "C:\BOXDLL.dll" ()
I get a bad DLL calling convention error, but if I declare it as long
long _stdcall someFunc()
{
return someVal;
}
and I declare it in VB as:
Declare Function someFunc Lib "C:\BOXDLL.dll" () As Long... this works. However, how can I tell VB that the function is of type void.
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Hi,
Ok figured out why I could not export void functions. I had to declare it as:
Declare Sub someFunc Lib "C:\BOXDLL.dll" () instead of Function. This is a very weird arrangement in my opinion.
Still no luck with exporting namespaces. Any help there would be greatly appreciated!
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Hi, everyone!
Here is a piece of code which is simply shows the usage of RAW socket. When capturing the package with Ethereal, it is often said bogus TCP header length (0, must be at least 20).
Please see what is wrong with my program.
Source code:
--------
/********************** main.c source file ************************/
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <stdio.h>
#pragma comment(lib, "ws2_32.lib")
struct tcpheader {
unsigned short int th_sport;
unsigned short int th_dport;
unsigned int th_seq;
unsigned int th_ack;
unsigned char th_x2:4, th_off:4;
unsigned char th_flags;
unsigned short int th_win;
unsigned short int th_sum;
unsigned short int th_urp;
}; /* total tcp header length: 20 bytes (=160 bits) */
struct ipheader {
unsigned char ip_hl:4, ip_v:4; /* this means that each member is 4 bits */
unsigned char ip_tos;
unsigned short int ip_len;
unsigned short int ip_id;
unsigned short int ip_off;
unsigned char ip_ttl;
unsigned char ip_p;
unsigned short int ip_sum;
unsigned int ip_src;
unsigned int ip_dst;
}; /* total ip header length: 20 bytes (=160 bits) */
// IP/TCP/UDP Checksum Function
USHORT checksum(USHORT *buffer, int size)
{
unsigned long cksum=0;
while (size > 1)
{
cksum += *buffer++;
size -= sizeof(USHORT);
}
if (size)
{
cksum += *(UCHAR*)buffer;
}
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >>16);
return (USHORT)(~cksum);
}
#define PORT 25
int main (void)
{
WSADATA wsd;
char datagram[4096];
int bOpt = 1;
if (WSAStartup(MAKEWORD(2,2), &wsd) != 0)
{
printf("WSAStartup() failed: %d\n", GetLastError());
return -1;
}
// Create a raw socket
SOCKET s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
if (s == INVALID_SOCKET)
{
printf("WSASocket() failed: %d\n", WSAGetLastError());
return -1;
}
struct ipheader *iph = (struct ipheader *) datagram;
struct tcpheader *tcph = (struct tcpheader *) datagram + sizeof (struct ipheader);
struct sockaddr_in sin;
sin.sin_family = AF_INET;
sin.sin_port = htons (PORT);
sin.sin_addr.s_addr = inet_addr ("2.3.4.5");
memset (datagram, 0, 4096); /* zero out the buffer */
iph->ip_hl = 5;
iph->ip_v = 4;
iph->ip_tos = 0;
iph->ip_len = sizeof (struct ipheader) + sizeof (struct tcpheader);
iph->ip_id = 1;
iph->ip_off = 0;
iph->ip_ttl = 255;
iph->ip_p = 6;
iph->ip_sum = 0;
iph->ip_src = inet_addr ("1.2.3.4");
iph->ip_dst = sin.sin_addr.s_addr;
tcph->th_sport = htons (1234);
tcph->th_dport = htons (PORT);
tcph->th_seq = rand();
tcph->th_ack = 0;
tcph->th_x2 = 0;
tcph->th_off = 5;
tcph->th_flags = 2; // SYN
tcph->th_win = htons(65535);
tcph->th_sum = 0;
tcph->th_urp = 0;
iph->ip_sum = checksum((unsigned short *)&iph, sizeof(ipheader) >> 1);
if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, (char *)&bOpt, sizeof(bOpt)) == SOCKET_ERROR)
{
printf("setsockopt(IP_HDRINCL) failed: %d\n", WSAGetLastError());
return -1;
}
while (1)
{
// Send The Packet
if (sendto(s, datagram, 40, 0, (SOCKADDR *)&sin, sizeof(sin)) == SOCKET_ERROR)
{
printf("sendto() failed: %d\n", WSAGetLastError());
return -1;
}
}
return 0;
}
/********************** main.c source file ************************/
--------
Thanks in advance,
George
|
|
|
|
|
Well, I've never done Raw before so I'm not sure how it's supposed to look but I changed:
George2 wrote:
struct tcpheader *tcph = (struct tcpheader *) datagram + sizeof (struct ipheader);
to this:
struct tcpheader *tcph = (struct tcpheader *) (datagram + sizeof (struct ipheader));
And here's what my sniffer captured, 2 frames:
5/01/2003 10:39:24 PM.7860
0000: 00 04 5A 20 E1 61 00 03 2F 07 5B 57 08 00 45 00 ..Z áa../.[W..E.
0010: 00 28 01 00 00 00 FF 06 B0 C2 01 02 03 04 02 03 .(....ÿ.°Â......
0020: 04 05 04 D2 00 19 29 00 00 00 00 00 00 00 50 02 ...Ò..).......P.
0030: FF FF 00 00 00 00 ÿÿ....
05/01/2003 10:39:25 PM.7256
0000: 00 04 5A 20 E1 61 00 03 2F 07 5B 57 08 00 45 00 ..Z áa../.[W..E.
0010: 00 28 01 00 00 00 FF 06 B0 C2 01 02 03 04 02 03 .(....ÿ.°Â......
0020: 04 05 04 D2 00 19 29 00 00 00 00 00 00 00 50 02 ...Ò..).......P.
0030: FF FF 00 00 00 00 ÿÿ....
Is that the way it's supposed to look?
|
|
|
|
|
I have a console application but I don't want that black window appear.I don't need to show anything to user.How can I prevent appearing it?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
|
Hi there, I am tryig to code a scan on IP adresses.
The scenario: there is application online, with a listener socket on a specific port. Another application is saerching for that application, only knowing the port but not the IP adresss.
So the searching appliaction has to loop thru a IP adress range to find the matching application.
The problem ist now, that such a "blind" connect on a IP-adress take a long time until a WSAETIMEDOUT error occurs and the application can go on.
Is there someone who got a good and fast solution?
(unfortunatly I can not start a directory server, because of some other reasons)
Thanks for help,
Best regards Andreas Niedermeier
|
|
|
|
|
Have you tried any of the WSAAsyncGetxxx() functions? That may not even be what you are looking for but the idea is to keep your program from blocking while it's checking. Another solution is a worker thread.
|
|
|
|
|
I don't know if you are developing or have the source code to the "application online" but if you are, why don't you just listen to a specific port -- not TCP/IP listen but UDP listen.
Just do a blocking or non-blocking recv or recvfrom in a thread for the port you want to receive communication from. Then the "searching application" can send a UDP broadcast to all computers on that subnet on that port. Since, his IP address will be the source in that packet, your listening thread in your non-searching application can take note of it and start a TCP/IP connection if required. Or, just send a reply to the "searching application" that you are there.
|
|
|
|
|
Hi everyone!
I want to use a class/struct to represent a TCP header
and another class/struct to represent a IP header. I also want
to write a checksum function for IP header and TCP header.
Someone suggesdted me to reference Libnet.
But it is too big!
My aim is simple, just represent TCP and IP header. And also
do a checksum for IP header and TCP header.
Are there some simple samples that I can refer?
Thanks in advance,
George
|
|
|
|
|
Hello,
I am developing a Dialog based application using MFC.
I have created a Modal Parent Dialog by using DoModal() method.
And also creating Modeless Child Dialogs by using Create() method.
Now I need to associate a unique id with every Child Dialog, so I could refer to them whenever I need them, by using their unique id's. Let say I want to focus one of the child dialog, or blink the caption bar.
Please anyonebody could help me in this regard
Regards
The Phantom. ™
|
|
|
|
|
Why don't you just use the pointers to the dialogs as a unique ID? If you really need some other way, you can try using SetDlgCtrlID() on the dialog, but the docs say it only works with child windows. You could try and see, but I would just use the pointers to the dialogs.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Hi, I'm having a crack at playing with the IXMLHTTPRequest interface, and I've got it mostly working, but the return type for one of the functions I need to use is BSTR, which, as I understand, is some sort of unicode string. How do I get it into a CString-friendly format?
NATHAN RIDLEY
Web Application Developer
generalgherkin@yahoo.com
|
|
|
|
|
it is assignable just write bstr = string.allocsysstring()
and yes..bstr is not a unicode string datatype..it is a binary datatype..binary string..
|
|
|
|
|
no, I mean I have the BSTR already but I want to create a CString out of it...
NATHAN RIDLEY
Web Application Developer
generalgherkin@yahoo.com
|
|
|
|
|
It's as simple as:
BSTR pbsz = L"Hello World";
CString str;
str = pbsz;
AfxMessageBox(str);
|
|
|
|
|
A BSTR is a null-terminated unicode string that is preceded by the it's length (similar to a Pascal-style string). However, the pointer actually points to the character data, so you have to decrement the pointer to read its length. However, you can just use wcslen() to get it's length exactly like a normal unicode string if you want.
To convert to a CString compatible string (LPCTSTR), use the W2T() ATL macro as such:
BSTR bstr;
LPCTSTR lpsz = W2T(bstr);
CString str = W2T(bstr);
If you don't want to use ATL, have a look at the WideCharToMultiByte() WIN32 function, but I prefer the ATL way - it's much simpler!
Hope this helps,
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Argh! I completely forgot that a BSTR may contain NULLs, so wcslen() may give you a length that is less than the length stored in the string itself. If this is the case, then you won't be able to operate on it like it was a CString. Just put in a test to see if the lengths are equal. If they are, then you can convert it to a CString like I said above. If not, then you'll have to find some other way... Hopefully I've given you enough information about BSTRs to find another way
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Hey thanks! Much appreciated Umm, forgive my ignorance, though, I get an undeclared identifier error on the W2T macro. I assume I'm missing a header file or something?
NATHAN RIDLEY
Web Application Developer
generalgherkin@yahoo.com
|
|
|
|
|
Nathan Ridley wrote:
I assume I'm missing a header file or something?
yep, atlconv.h
Make sure you read my reply to my reply (I hope that makes sense ) for some stuff that I forgot about in my first reply.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
[Short Homer Scream]AARGH![/Short Homer Scream]
I get these errors...
D:\cdev\XMLTest\XMLTestDlg.cpp(195) : error C2065: '_lpw' : undeclared identifier
D:\cdev\XMLTest\XMLTestDlg.cpp(195) : error C2440: '=' : cannot convert from 'unsigned short *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
D:\cdev\XMLTest\XMLTestDlg.cpp(195) : error C2065: '_convert' : undeclared identifier
My code looks like this:
void CXMLTestDlg::OnButton1()
{
IXMLHTTPRequest* pIXMLHttpRequest = NULL;
HRESULT hr = CoInitialize(NULL);
hr = CoCreateInstance( CLSID_XMLHTTP,
NULL,
CLSCTX_INPROC_SERVER,
IID_IXMLHTTPRequest,
(void**)&pIXMLHttpRequest);
BSTR bstrString = NULL;
try
{
hr = pIXMLHttpRequest->open(_bstr_t(_T("GET")),
_bstr_t(_T("http://top01wdt1:8090/test.htm")),
_variant_t(VARIANT_FALSE),
_variant_t(""),
_variant_t(""));
if(SUCCEEDED(hr)) {
BSTR* pbsz = NULL;
hr = pIXMLHttpRequest->get_responseText(pbsz);
LPCTSTR lpsz = W2T(*pbsz);
CString x(lpsz);
m_szOutput = test;
UpdateData(FALSE);
}
}
catch(...)
{
MessageBox("Failure!");
}
}
NATHAN RIDLEY
Web Application Developer
generalgherkin@yahoo.com
|
|
|
|
|
Oops. Forgot one thing.
put USES_CONVERSION; at the top of your function. This macro declares the variables that the W2T macro (and all the other ATL conversion macros) use internally.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
cool, thanks for the help!
NATHAN RIDLEY
Web Application Developer
generalgherkin@yahoo.com
|
|
|
|
|
In the code I've posted (in the message that this message is a reply to) there is a bug in the bold section which causes an exception to occur. It says I'm trying to write to memory address 0x00000000, and only occurs once I try to read the value of pbsz. Can you see any obvious points where this could be caused?
NATHAN RIDLEY
Web Application Developer
generalgherkin@yahoo.com
|
|
|
|
|