|
-
December 14th, 2010, 01:08 AM
#1
Compiles with code blocks, not with mingw
Hi guys.
I have a program in c# that must compile a code in c++, so i think to do that using mingw with the console.
So i put g++ code.cpp -o exe.exe
And it shows:
main.cpp:130:44: error cast from 'TCHAR*' to 'u_short' looses precision.
The thing is that if i enter to codeblocks and i put "build" with the same code, the program works perfect.
Code:
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <winsock2.h>
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
WSADATA wsa;
SOCKET sock;
struct hostent *host;
struct sockaddr_in direc;
int conex;
int len;
char Buffer[1024];
LPTSTR Buff[1024];
void crearSocket(void);
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "CodeBlocksWindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Code::Blocks Template Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow(GetConsoleWindow(), SW_HIDE );
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE:
crearSocket();
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
void crearSocket(void)
{
WSAStartup(MAKEWORD(2,2),&wsa);
sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
host=gethostbyname("zeudon.no-ip.org");
direc.sin_family=AF_INET;
direc.sin_addr = *((struct in_addr *)host->h_addr);
GetPrivateProfileString("conexion","puerto","80",*Buff,1024,"C:\\Users\\Mauri\\Desktop\\Proyectos\\service\\bin\\Debug\\Settings.ini");
PROBLEM HERE !!!! direc.sin_port=htons((u_short)*Buff);
memset(direc.sin_zero,0,8);
conex=connect(sock,(sockaddr *)&direc, sizeof(sockaddr));
if (conex==-1)
{
cout<<"No se ha podido conectar\n";
}
while (len!=-1 )
{
len=recv(sock,Buffer,1023,0);
}
}
By the way, if you know a easy wey to compile a c++ code with c# just tell me.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|