2012年9月4日 星期二

Chrome error: Uncaught Syntax Error: Unexpected Token ILLEGAL

A html is working fine on IE, but can't work in Chrome and firefox.

Using console shows Chrome Uncaught Syntax ErrorUnexpected Token ILLEGAL.

Solution: check whether the format of html is UTF-8 or not. Save as UTF-8 format should be fixed.

2012年8月22日 星期三

CHtmlDialog invoke javascript in HTML


CComPtr<IHTMLDocument2> spDoc;
GetDHtmlDocument(&spDoc);
CComPtr<IDispatch> spDisp(NULL);

if(spDoc)
{
spDoc->get_Script(&spDisp);
}


CComBSTR bstrMember(csFunctionName);
DISPID dispid = NULL;
HRESULT hr = spDisp->GetIDsOfNames(IID_NULL,
  &bstrMember,
  1,
  LOCALE_SYSTEM_DEFAULT,
  &dispid);
if(FAILED(hr))
{
//ShowError(GetSystemErrorMessage(hr));
return ;
}

CStringArray csParamArray;
csParamArray.Add(csParam1);
csParamArray.Add(csParam2);
const int arraySize = csParamArray.GetSize();

DISPPARAMS dispparams;
memset(&dispparams, 0, sizeof dispparams);
dispparams.cArgs = arraySize;
dispparams.rgvarg = new VARIANT[dispparams.cArgs];


for( int i = 0; i < arraySize; i++)
{
CComBSTR bstr = csParamArray.GetAt(arraySize - 1 - i); // back reading
bstr.CopyTo(&dispparams.rgvarg[i].bstrVal);
dispparams.rgvarg[i].vt = VT_BSTR;
}
dispparams.cNamedArgs = 0;

EXCEPINFO excepInfo;
memset(&excepInfo, 0, sizeof excepInfo);
    CComVariant vaResult;
UINT nArgErr = (UINT)-1;  // initialize to invalid arg
       
hr = spDisp->Invoke(dispid,IID_NULL,0,
DISPATCH_METHOD,&dispparams,&vaResult,&excepInfo,&nArgErr);

delete [] dispparams.rgvarg;

2012年6月4日 星期一

Using jsoncpp to parse json


bool CIPCamSD::bParseSDListCGI(CString csResponse)
{
CString csStatus,csPath;
int nTotalFileNum(0), nTotalPage(0), nNumOfFilesInList(0), nNumOfPage,nPageSize(0);
Json::Reader jReader;
Json::Value jsonRoot;
   
bool bOK = jReader.parse(strGetStdString(csResponse), jsonRoot);
Json::ValueType jsonType = jsonRoot.type();


if(jsonRoot.type() == Json::ValueType::objectValue && jsonRoot.type() == Json::ValueType::objectValue)
{
// get string value
if(jsonRoot.get("status", Json::Value()).type() != Json::ValueType::nullValue)
{
csStatus = CString(jsonRoot.get("status", "").asCString());
if(csStatus != _T("ready"))
return false;
}
if(jsonRoot.get("path", Json::Value()).type() != Json::ValueType::nullValue)
{
csPath = CString(jsonRoot.get("path", "").asCString());

}

// get int value, not working so using _ttoi and cstring
if(jsonRoot.get("page", Json::Value()).type() != Json::ValueType::nullValue)
{
nNumOfPage = _ttoi(CString(jsonRoot.get("page", "" ).asCString()));
}

if(jsonRoot.get("pagesize", Json::Value()).type() != Json::ValueType::nullValue)
{
nPageSize = _ttoi(CString(jsonRoot.get("pagesize", "").asCString()));
}

if(jsonRoot.get("total_num", Json::Value()).type() != Json::ValueType::nullValue)
{
nTotalFileNum = _ttoi(CString(jsonRoot.get("total_num", "").asCString()));
}

if(jsonRoot.get("total_page", Json::Value()).type() != Json::ValueType::nullValue)
{
nTotalPage =  _ttoi(CString(jsonRoot.get("total_page", "").asCString()));
}

if(jsonRoot.get("num",   Json::Value()).type() != Json::ValueType::nullValue)
{
nNumOfFilesInList =  _ttoi(CString(jsonRoot.get("num", "").asCString()));
}

// get array value
//"list":[{"name":"20120530_183043_S_C.avi","type":"file","time":"2012-05-30 18:34:10","trigger":"Schedule","size":"104905226"}
if(jsonRoot.get("list", Json::Value()).type() != Json::ValueType::nullValue && jsonRoot.get("list", Json::Value()).type() == Json::ValueType::arrayValue)
{
 CString csName,csType,csFileEndTime,csTrigger;
 //Json::Value jsonList = jsonRoot.get("list", Json::Value());
 Json::Value jsonList = jsonRoot["list"];
 for (int index = 0; index < jsonList.size(); index++)
 {
CString csName,csType,csTime,csTrigger;
int nSize(0);
if(jsonList[index].type() != Json::ValueType::nullValue)
{
Json::Value jsonListInfo = jsonList[index];
if(jsonListInfo.get("name", Json::Value()).type() != Json::ValueType::nullValue)
{
csName = jsonListInfo.get("name", "").asCString();
}

if(jsonListInfo.get("type", "").type() != Json::ValueType::nullValue)
{
csType = jsonListInfo.get("type", "").asCString();
}

if(jsonListInfo.get("time", Json::Value()).type() != Json::ValueType::nullValue)
{
csFileEndTime = jsonListInfo.get("time", "").asCString();
}

if(jsonListInfo.get("trigger", Json::Value()).type() != Json::ValueType::nullValue)
{
csTrigger = jsonListInfo.get("trigger", "").asCString();
}

if(jsonListInfo.get("size", Json::Value()).type() != Json::ValueType::nullValue)
{
nSize = _ttoi(CString(jsonListInfo.get("size", Json::Value()).asCString()));
}


}
 }
}
}

return false;
}

2012年5月31日 星期四

Using jsoncpp with VS2008


在專案使用jsoncpp build過程一些筆記:
1. Debug版沒什麼問題 直接用就好

2. Release版 首先要把Project properties->configuration properties->C/C++->code generation 改成/MT
但在我的project裡面用MT會有錯誤,我的project是使用Multi threaded DLL/MD
所以要把jsoncpp也改成MD(如下圖)。不知道是不是要跟project配合,沒實驗。













3. compile自己的專案會出現以下error
Error 857 fatal error C1083: Cannot open compiler generated file: '../../build/vs71/Release/lib_json\json_reader.asm': No such file or directory d:\jsoncpp-src-0.6.0-rc2\src\lib_json\json_reader.cpp 1
有兩個solution:
(1)將jsoncpp中build/vs71那個folder拉到跟error msg一樣的位置。這個case就是往上拉兩個folder層級。
(2)或到jsoncpp的project properties->configuration properties->C/C++->Output Files
將Assembler output改成No Listing就不會出現錯誤了。(如下圖)










//==============
簡單記一下VS2008使用lib的方法
1.先include header檔
Project properties->configuration properties->C/C++->General->Additional include directories
加入.\include所在目錄
2.Linker加入lib檔
Project properties->configuration properties->Linker->General->Additional Library dependencies
加入.\lib所在目錄
Project properties->configuration properties->Linker->Input->Additional dependencies 
加入.lib檔案名稱

也可以加入command line指令或用vs2008中tools->options->Projects and solutions->vc++ directories加入lib跟inlcude路徑。

2012年2月20日 星期一

None Border Dialog drag moving method

Set the dialog "Border" property to none , re-sizing or thin the dialog won't be able to be dragged moving

If you don't want the border of a dialog but also need the dragging feature, send WM_NCLBUTTONDOWN Message @ OnLButtonDown();


void CDlgExample::OnLButtonDown(UINT nFlags, CPoint point)
{
SendMessage(WM_NCLBUTTONDOWN,HTCAPTION,0);
CDialog::OnLButtonDown(nFlags, point);
}

2012年1月17日 星期二

LoadLibrary

@ DLL
extern "C" __declspec(dllexport) double SquareRoot(double d);

@ caller

typedef double (SQRTPROC) (double);
SQRTPROC* pFunc;
HMODULE hMod = ::LoadLibrary(_T("xxx.dll"));

if(hMod)
{
    pFunc = (SQRTPROC*)::GetProcAddress(hMod, " SquareRoot ");
    if(pFunc)
       double d = (*pFunc)(1.0);
}