C++ file cfx_pmta.cxx won't compile - c++

I am trying to compile the PMTA cfx_pmta.cxx file so I can make some changes but I can't get it to compile before I have even made any changes.
Here are the includes at the to of the file:
#if defined(sun)
#define _POSIX_PTHREAD_SEMANTICS
#endif
#ifdef _WIN32
#include <windows.h>
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#if defined(UNIT_TEST)
#define __dllexport
#else
#define __dllexport __declspec(dllexport)
#endif
#else
#define __dllexport
#define __cdecl
#endif
#ifdef __unix__
#include <signal.h>
#include <errno.h>
#endif
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#if defined _WIN32
#include <time.h>
#endif
#include "stdafx.h"
#include "cfx.h"
#include "include/submitter/PmtaMsg.h"
#include "include/submitter/PmtaConn.h"
#include "include/submitter/PmtaRcpt.h"
229 Error C2079 'tmp' uses undefined class 'std::basic_ostringstream,std::allocator>'
230 Error C2297 '<<': illegal, right operand has type 'const char [9]'
230 Error C3861 'time': identifier not found
230 Warning C4552 '<<': operator has no effect; expected operator with side-effect
231 Error C2228 left of '.str' must have class/struct/union
229 std::ostringstream tmp;
230 tmp << "boundary" << time(0);
231 std::string boundary = tmp.str();
617 Error C2079 'f' uses undefined class 'std::basic_ifstream>'
617 Error C2440 'initializing': cannot convert from 'const char *' to 'int'
625 Error C2228 left of '.read' must have class/struct/union
626 Error C2228 left of '.gcount' must have class/struct/union
629 Error C2228 left of '.close' must have class/struct/union
621 Error C4996 'strerror': This function or variable may be unsafe. Consider using strerror_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
604 void
605 attachFile(const std::string& boundary, const char* fileName) {
606 addBoundary(boundary);
607 addData("Content-Type: application/octet-stream\n");
608 addData("Content-Disposition: attachment; filename=\"");
609 addData(fileName); addData("\"\n");
610 addData("Content-Transfer-Encoding: base64\n\n");
611
612 if (!PmtaMsgSetEncoding(_message, PmtaMsgENCODING_BASE64)) {
613 die("error setting base64 encoding", PmtaMsgGetLastError(_message));
614 }
615
616 char buffer[8192];
617 std::ifstream f(fileName);
618
619 if (!f) {
620 std::string error = std::string("error opening ") + fileName;
621 die(error, strerror(errno));
622 }
623
624 while (f) {
625 f.read(buffer, sizeof(buffer));
626 addData(buffer, static_cast<int>(f.gcount()));
627 }
628
629 f.close();
630
631 if (!PmtaMsgSetEncoding(_message, PmtaMsgENCODING_8BIT)) {
632 die("error setting 8-bit encoding", PmtaMsgGetLastError(_message));
633 }
634 }
736 Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
736 Error C2144 syntax error: 'void' should be preceded by ';'
733 //------------------------------------------------------------------------------
734 // externally visible tag processor
735//------------------------------------------------------------------------------
736 extern "C" __dllexport void __cdecl
737 ProcessTagRequest(CCFXRequest* request) {
738 try {
739 TagProcessor proc(request);
740 proc.process();
741 }
742 catch (std::bad_alloc&) {
743 request->ThrowException(TAG_ERROR, "out of memory");
744 }
745 catch (char* text) {
746 // this may be thrown by some dummy classes
747 request->ThrowException(TAG_ERROR, text);
748 }
749 catch (CCFXException* e) {
750 request->ReThrowException(e);
751 }
752 catch (...) {
753 // original ColdFusion example comment:
754 // "Catch ALL other exceptions and throw them as Cold Fusion exceptions
755 // (DO NOT REMOVE! -- this prevents the server from crashing in case of
756 // an unexpected exception)"
757 request->ThrowException(TAG_ERROR, "Unexpected error occurred "\
758 "while processing tag.");
759 }
760 };
Any help would be a great!! Just need to be able to get it to compile the DLL and then I can make the changes needed.
Also I'm not a C++ dev so trying to get my head round it, so go easy.

std::cout is a output stream which is defined within the <iostream> header.
in order to use std::string objects you have to include the <string> header
Try adding:
#include<iostream>
#include<string>
In your cxx file.

After some reading I decided to try the Command Line compiler and to my amazement it compiled fine.
So if anyone is intrested in how to recompile the cfx_pmta.cxx file for PMTA to change the Cold Fusion custom tag code run the following command (obviously changing path to match your file locat
cl /LD /MT /EHsc /IC:\path\api\include /IC:\ColdFusion8\include /D "_WIN32" C:\path\api\cfx_pmta.cxx /link C:\path\api\lib\pmta.lib ws2_32.lib advapi32.lib

Related

C/C++ - working with interrupts in visual studio c++

I am a computer science student and recently learned how to use interrupts in C.
after a couple of search in web I came up with this code:
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
#define INTR 0x1c
#define gotoxy(x,y) printf("\033[%d;%dH", (x), (y))
//#define clear() printf("\033[H\033[J");
/*
//positioning
void gotoxy(int x, int y)
{
printf("%c[%d;%df",0x1B,y,x);
}
*/
void interrupt handler(__CPPARGS);
void interrupt ( *oldhandler)(__CPPARGS);
int countS = 0;
int s = 0;
int m = 0;
int ms = 0;
int l = 0;
int flag = 0;
int main(void)
{
clrscr();
printf("%02d:%02d:%02d",m,s,ms);
oldhandler = getvect(INTR);
setvect(INTR, handler);
char c;
while(1)
{
c = getch();
switch(c){
case 'e':
goto exit_loop;
break;
case ' ':
flag = 1-flag;
break;
case 'r':
flag = s = m = ms = l = 0;
clrscr();
printf("%02d:%02d:%02d",m,s,ms);
break;
case 'l':
gotoxy(++l,0);
printf("%02d:%02d:%02d",m,s,ms);
break;
}
}
exit_loop:;
setvect(INTR, oldhandler);
return 0;
}
void interrupt handler(__CPPARGS)
{
if(flag == 1){
countS++;
ms += 55;
if(countS == 18)
{
countS = ms = 0;
s++;
if(s==60)
{
m++;
s = 0;
}
}
gotoxy(0,0);
printf("%02d:%02d:%02d",m,s,ms);
}
}
this code is some kind of stopwatch in C console application and its work perfect in historical Turbo C++.
I changed my IDE and now using Visual studio 2013, when i create a new project in Visual C++->win32ConsoleApplication and paste this code in the main file. its not work. then an error says that i should add #include "stdafx.h" in the first of my file. after doing so, this is my main error list:
Error 1 error C2146: syntax error : missing ';' before identifier 'handler' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32 1 ConsoleApplication1
Error 2 error C2182: 'interrupt' : illegal use of type 'void' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32 1 ConsoleApplication1
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32 1 ConsoleApplication1
Error 4 error C2065: 'oldhandler' : undeclared identifier c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1
Error 6 error C2086: 'int interrupt' : redefinition c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1
Error 7 error C2143: syntax error : missing ';' before '(' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1
Error 8 error C2059: syntax error : ')' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1
Error 9 error C2059: syntax error : ';' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33 1 ConsoleApplication1
Error 10 error C3861: 'clrscr': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 44 1 ConsoleApplication1
Error 11 error C2065: 'oldhandler' : undeclared identifier c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 46 1 ConsoleApplication1
Error 12 error C3861: 'getvect': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 46 1 ConsoleApplication1
Error 13 error C3861: 'setvect': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 48 1 ConsoleApplication1
Error 14 error C3861: 'clrscr': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 67 1 ConsoleApplication1
these errors are related to these lines:
void interrupt handler(__CPPARGS);
void interrupt ( *oldhandler)(__CPPARGS);
and using of: clrscr();
my operation system is windows 10-64bit and its my first time programming in c/c++ in visual studio. I do some in Turbo c++ and devC++ before but only Turbo c++ run this sample and not even devC++. what is the diffrenses and how should I solve this?
thanks
You are working in 64-bit long mode, so you don't have access to real-mode BIOS interrupts or MS-DOS services. Your code has a number of other issues but the bottom line is it's not going to work without a 16-bit compiler and an emulator (like the NTVDM which is absent on 64-bit Windows)

checking internet connection in c++ using internetcheckconnection

I am trying to check internet connection of the user by using internetcheckconnection().
The code:
#include <Wininet.h>
#include <iostream>
#include <string.h>
#include <windows.h>
#pragma comment(lib, "wininet.lib")
int main()
{
char url[128];
strcat(url, "http://www.techtoolbox.com");
bool bConnect = InternetCheckConnection(url, FLAG_ICC_FORCE_CONNECTION, 0);
if (bConnect) {
//internet connection exists !
std::cout << "yes";
}
else {
std::cout << "no ";
}
return 0;
}
But many error are coming up like
29 11 C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\Wininet.h [Error] 'LPVOID' does not name a type
30 11 C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\Wininet.h [Error] 'HINTERNET' does not name a type
32 11 C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\Wininet.h [Error] 'WORD' does not name a type
and 431 more .
I have already installed Wininet.lib, but still these error are coming . It would be kind of you if you could solve this easy problem :) .
LPVOID, HINTERNET and other types from your error messages are declared in windows.h. You should rearrange includes to fix these errors:
#include <windows.h>
#include <Wininet.h>

std::mutex::try_lock hangs when called from a static object constructor in a DLL

This happens with the MSVC 2013 compiler. I have a solution with 2 projects: .exe and .dll.
The .exe source code:
extern "C" int test_dll();
int main() {
test_dll();
return 0;
}
The .dll source code:
#include <mutex>
struct AAAA {
AAAA() {
std::mutex mutex;
if (mutex.try_lock()) { // always blocks
mutex.unlock();
}
};
} globalObject;
extern "C" __declspec(dllexport)
int test_dll() {
return true;
}
The try_lock call never returns. Here's the call stack:
msvcr120d.dll!Concurrency::details::ThreadScheduler::Create(const Concurrency::SchedulerPolicy & policy) Line 34
msvcr120d.dll!Concurrency::details::SchedulerBase::CreateWithoutInitializing(const Concurrency::SchedulerPolicy & policy) Line 285
msvcr120d.dll!Concurrency::details::SchedulerBase::GetDefaultScheduler() Line 654
msvcr120d.dll!Concurrency::details::SchedulerBase::CreateContextFromDefaultScheduler() Line 571
msvcr120d.dll!Concurrency::details::SchedulerBase::CurrentContext() Line 399
msvcr120d.dll!Concurrency::details::LockQueueNode::LockQueueNode(unsigned int timeout) Line 619
msvcr120d.dll!Concurrency::critical_section::try_lock() Line 1049
msvcp120d.dll!mtx_do_lock(_Mtx_internal_imp_t * * mtx, const xtime * target) Line 75
msvcp120d.dll!_Mtx_trylock(_Mtx_internal_imp_t * * mtx) Line 162
MutexDll.dll!std::_Mtx_trylockX(_Mtx_internal_imp_t * * _Mtx) Line 73
MutexDll.dll!std::_Mutex_base::try_lock() Line 46
MutexDll.dll!AAAA::AAAA() Line 8
MutexDll.dll!`dynamic initializer for 'AAA''() Line 21
[External Code]
This doesn't happen if the global object is created in the main .exe project. Only when in the DLL. What's going on here?
The hang doesn't occur with the MSVC2015 compiler (v140 toolset).

mErrCount: Identifier not found although it is declared in the include path of Project properties

This is my code named test.cpp
#include <test.h>
namespace ScStdTb {
#define CFG_REG 0
#define CMD_REG 0x4
#define CTRL_REG 0x8
#define STAT_REG 0xC
void BasicTB::test()
{
void testCase();
}
void testCase()
{
unsigned int data = 0x0;
data=1;
REG_WRITE(CTRL_REG,&data);
}
}
REG_WRITE is a macro defined in TbCommBase.h
Here is the code snippet from that:
/*macro for register read/write*/
#define REG_WRITE(reg, value) \
if (send_transaction((reg), value, B_WR)) {\
mErrCount++;\
PRINT_DBG("Write failed : Reg at 0x"<< hex << (reg)\
<<", data 0x"<< value << dec);\
} else {\
wait_delta();\
}
In the project properties I have added the path to TbCommBase.h under
Project -> Properties -> Configuration Properties -> C/C++ -> Additional Include Directories.
Also mErrCount is defined in TbCommBase.h
unsigned int mErrCount;
When I try to compile test.cpp I get the following errors:
error C2065: 'mErrCount' : undeclared identifier
error C3861: 'send_transaction': identifier not found
error C3861: 'name': identifier not found
error C3861: 'wait_delta': identifier not found
There is no error in the file TbCommBase.h as such. It only shows undeclared identifier only in test.cpp although I have referenced to the header. I have executed a previous file similarly without any issues.
Any ideas ?
In the end it was pretty simple. The scope resolution operator caused the problem.
Here is the updated code.
#include <ifxPkcTest.h>
namespace ScStdTb {
#define CFG_REG 0
#define CMD_REG 0x4
#define CTRL_REG 0x8
#define STAT_REG 0xC
void BasicTB::test()
{
void testCase();
}
void BasicTB::testCase() //SOLUTION
{
unsigned int data = 0x0;
data=1;
REG_WRITE(CTRL_REG,&data);
}
}

use macro token in pragma result in incorrect substitution

I'm trying to use macro with "pragma include_alias" in VS2010, but I got a odd compiling warning which means the substitution is incorrect.
Here is the code:
18 #define RAPID_INCLUDES_PATH(MY_TARGET_HEADERS) "C:\\thirdpart\\rapidxml-1.13\\" ## #MY_TARGET_HEADERS
19 #define TEST(empty) "C:\\thirdpart\\rapidxml-1.13\\rapidxml_print.hpp"
//WORKS
21 #pragma include_alias( "rapidxml.hpp", "C:\\thirdpart\\rapidxml-1.13\\rapidxml.hpp" )
22 #pragma include_alias( "rapidxml_print.hpp" , TEST(empty) )
//FAILS
23 #pragma include_alias( "rapidxml_utils.hpp" , RAPID_INCLUDES_PATH(rapidxml_utils.hpp) )
24 #pragma include_alias( "rapidxml_iterators.hpp" , RAPID_INCLUDES_PATH(rapidxml_iterators.hpp) )
26 #include "rapidxml.hpp"
27 #include "rapidxml_iterators.hpp"
28 #include "rapidxml_print.hpp"
29 #include "rapidxml_utils.hpp"
The error messages:
1> Touching "Debug\xml2.unsuccessfulbuild".
1>ClCompile:
1> stdafx.cpp
1>d:\workspace\v10\xml2\xml2\stdafx.h(23): warning C4081: expected ')'; found 'string'
1>d:\workspace\v10\xml2\xml2\stdafx.h(24): warning C4081: expected ')'; found 'string'
1>d:\workspace\v10\xml2\xml2\stdafx.h(27): fatal error C1083: Cannot open include file: 'rapidxml_iterators.hpp': No such file or directory
1>
1>Build FAILED.
1>
It seems there're some misuses of macro.
Anyone knows how to fix it? Thanks a lots.