|
Hi EveryOne,
In ActivexDLL I have written a method called Connect(..)inside a class. The method exposes the functionality of connecting to another system using sockets.
The problem here is when I compile my project I am getting link errors(unresolved external symbol). These errors are thrown when winsocks methods are called like htos(),inet_addr(),connect() are called.
Unresolved symbol (upto my knowledge) are thrown when the function definition is unknown or its different from the one that is implemented. since I am using an inbuild function (used the header file winsock2.h) what might be the cause to the problem? How would I Overcome it. Please find the code below.
STDMETHODIMP CRAPClientX::Connect(BSTR serverIP, BSTR serverPort,BSTR *output)<br />
{<br />
<br />
<br />
WSADATA wsaData;<br />
char returnString[150];<br />
<br />
int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);<br />
if (iResult != NO_ERROR)<br />
printf("Error at WSAStartup()\n");<br />
<br />
<br />
SOCKET ConnectSocket;<br />
<br />
ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);<br />
<br />
if (ConnectSocket == INVALID_SOCKET) <br />
{<br />
sprintf(returnString,"Error at socket(): %ld\n", WSAGetLastError()); <br />
*output=SysAllocString(_bstr_t(returnString)); <br />
WSACleanup();<br />
return S_OK;<br />
}<br />
<br />
<br />
sockaddr_in clientService; <br />
<br />
clientService.sin_family = AF_INET;<br />
<br />
clientService.sin_addr.s_addr = inet_addr("127.0.0.1" );<br />
<br />
clientService.sin_port = htons( 27015 );<br />
<br />
<br />
if ( connect(ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR) <br />
{<br />
sprintf( returnString,"Failed to connect.\n" );<br />
*output=SysAllocString(_bstr_t(returnString));<br />
WSACleanup();<br />
return S_OK;<br />
}<br />
<br />
sprintf(returnString,"Connected to server.\n");<br />
*output=SysAllocString(_bstr_t(returnString)); <br />
WSACleanup();<br />
return S_OK;<br />
}<br />
kinldy reply.
Regards,
LG.
lgatcodeproject
|
|
|
|
|
lgatcodeproject wrote: Unresolved symbol (upto my knowledge) are thrown when the function definition is unknown or its different from the one that is implemented. since I am using an inbuild function (used the header file winsock2.h) what might be the cause to the problem?
Not linking to the lib file in which these functions are defined might be one cause . So, did you link your project to ws2_32.lib ?
|
|
|
|
|
Cedric
Once I posted this question, I got the question which u asked; in my mind and then included the library (which I missed out earlier )WS2_32.LIB. So I fixed it in the time you answered the question. sorry for wasting your time Cedric and thanks for the reply.
Regards,
LG.
lgatcodeproject
|
|
|
|
|
|
In fact, I had to open a project in which I'm using sockets to recall the name
|
|
|
|
|
So guess its toooo much of Memory Recall hapenning today hmmm
Regards,
LG.
lgatcodeproject
|
|
|
|
|
Hello,
I am using Visual Studio 2008. I have to create a DLL in Project Type Visual C++ and i have to call this dll in Windows Forms Application Template.
Which Template i have to select to create dll:- Class Library or MFC DLL?
How i can call or import this dll in my Windows Forms Application?
Plz help me.
|
|
|
|
|
MSDN[^] should help you if nobody does and sometimes nothing helps. Not even MSDN .
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
Windows Forms Application is a CLR project - that means it's managed/.NET.
Use the appropriate DLL project - If you're using MFC, make an MFC DLL.
If using just Win32 in your DLL, make a Win32 console project and add the
appropriate Windows DLL code. etc....
Nikesh Jagtap wrote: How i can call or import this dll in my Windows Forms Application?
It depends on what your DLL exposes as an interface. If your DLL has
managed interfaces it's easy. Unmanaged may require some kind of interop
from the managed code.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
can hdc be passed between processes?
dont want,dont want thinking,climbing on head and jumping grass!
(venda venda ennu vicharikumbol thellayill keyaree chadunnoda pulle!)
|
|
|
|
|
I don't think so, but in general it's not a problem: simply conjure up one in the target process from the HWND in question (HWND s can be shared between processes).
Steve
|
|
|
|
|
Hi all,
Anyone can tell me how can set back image in ListCtrl while view of ListCtrl is Report view.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
I haven't tried it but isn't CListCtrl::SetBkImage good enough? Have you tried this?
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hai,
I am very new in VC++/MFC Programming. I have a problem to load a high resolution icon and Png Image to toolbar. How can i load. please tell me any article or help with examples link.
Regards
Bagavathikumar
Bagavathikumar
|
|
|
|
|
|
You can test with follow code lines:
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_TOOLBAR))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
//m_ImgList is a variable type CImageList
m_ImgList.Create(32, 32, ILC_COLOR32, 0, 10); //ILC_COLOR32 specifies the high color of 32 bits
m_ImgList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
m_ImgList.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
m_ImgList.Add(AfxGetApp()->LoadIcon(IDI_ICON3));
CToolBarCtrl& tbCtrl = m_wndFormatBar.GetToolBarCtrl();
tbCtrl.SetImageList(&m_ImageList);
|
|
|
|
|
Can anyone help me on how to create log file in Visual C++ with MFC???
|
|
|
|
|
log files are just simple text files unless you want to create complicated ones. I usually enter the date/time at the beginning of the log entry and then the file name, function name and the Log message. You can use normal fstream objects to write to the file. The log function should open the log file, write the log entry then close it again.
In case you are looking for something complicated try to create a service for logging messages to a log file.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
cb02061 wrote: Can anyone help me on how to create log file in Visual C++ with MFC???
In exactly the same way as you would any other file. What name you give the file, or what you put into it, is irrelevant.
Hint: see the CFile class.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
This is so terribly embarrassing. An old dog like myself shouldn't be asking such stupid questions, but for the life of me I'm can't find the right switch to flip. Of course, I knew I was in trouble when I heard myself mutter, "All I wanted to do was..."
IE7 has a convoluted Ctrl+Alt+F4 combination to close all but the current tab (best as I can determine from Google, etc., there is no Tabs API, bizarre as that may be). So, in a toolbar I wrote, I simply wanted to add a button so the user could click to close all tabs instead of playing a game of Twister with their fingers. WM_KEYDOWN, SendInput, Get/SetKeyboardState, I've screwed around with all of this, but I can't seem to find the proper approach to send this particular keystroke combination. Of course, it's the combination of Ctrl and Alt that is the complicating factor.
So, how 'bout it - any of you old dogs (or all the young dogs who are much brighter than I am) know how to accomplish this? It really feels like one of those solutions that's going to be so simple as to make me feel quite inept once discovered, but hey, I've been there before.
Thanks for any insights you might offer.
|
|
|
|
|
I don't know how to send keys but there is an article KeyStrokeEngine[^]. I just tried the demo application and it can successfully send CTRL+ALT+F4 to IE. Maybe looking into source will tell you how to post a message yourself.
-Saurabh
modified on Tuesday, April 29, 2008 10:36 PM
|
|
|
|
|
Hi, Saurabh.
I looked over his code, seems to be a nice piece of work. Reviewing it put me onto keybd_event(), which is an approach I hadn't been aware of (probably because it's been superceded by the somewhat more convoluted SendInput()).
keybd_event() is pretty straightforward to use, and when I plugged in the key down and then key up calls for control, alt and F4, it worked like a charm.
For those who may be interested, here's the snippet that got it done:
<br />
keybd_event(VK_CONTROL,0x9d,0 , 0);<br />
keybd_event(VK_MENU,0xb8,0 , 0);<br />
keybd_event(VK_F4,0,0 , 0);<br />
<br />
keybd_event(VK_CONTROL,0x9d,KEYEVENTF_KEYUP,0);<br />
keybd_event(VK_MENU,0xb8,KEYEVENTF_KEYUP,0);<br />
keybd_event(VK_F4,0, KEYEVENTF_KEYUP,0);<br />
Thanks very much for taking the time to help me - I do appreciate it!
|
|
|
|
|
Hey Chris,
You are most welcome and thanks for the code snippet.
-Saurabh
|
|
|
|