⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winmsiwrapper.cpp

📁 JDesktop Integration Components (JDIC)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * Class:     WinMsiWrapper * Method:    MsiCloseAllHandles * Signature: ()I */JNIEXPORT jint JNICALL Java_org_jdesktop_jdic_packager_impl_WinMsiWrapper_msiCloseAllHandles  (JNIEnv * env, jclass jc){    return MsiCloseAllHandles();}    /* * Class:     org_jdesktop_jdic_packager_impl_WinMsiWrapper * Method:    MsiDatabaseGenerateTransform * Signature: ()I */JNIEXPORT jint JNICALL Java_org_jdesktop_jdic_packager_impl_WinMsiWrapper_msiDatabaseGenerateTransform(JNIEnv * env, jclass jc, jint hDatabase, jint hDatabaseReference, jbyteArray transformFile){	int errorCode = -1;	//Constructs the paramter	LPCTSTR szTransformFile = (LPCTSTR) env->GetByteArrayElements(transformFile, NULL);	//Windows API invocation	errorCode = MsiDatabaseGenerateTransform((MSIHANDLE) hDatabase, (MSIHANDLE) hDatabaseReference, (LPCTSTR)szTransformFile, 0, 0);	//Release the string	env->ReleaseByteArrayElements(transformFile, (signed char*)szTransformFile, 0);	return errorCode;}/* * Class:     org_jdesktop_jdic_packager_impl_WinMsiWrapper * Method:    MsiCreateTransformSummaryInfo * Signature: ()I */JNIEXPORT jint JNICALL Java_org_jdesktop_jdic_packager_impl_WinMsiWrapper_msiCreateTransformSummaryInfo(JNIEnv * env, jclass jc, jint hDatabase, jint hDatabaseReference, jbyteArray transformFile){	int errorCode = -1;	//Constructs the paramter	LPCTSTR szTransformFile = (LPCTSTR) env->GetByteArrayElements(transformFile, NULL);	//Windows API invocation	errorCode = MsiCreateTransformSummaryInfo((MSIHANDLE) hDatabase, (MSIHANDLE) hDatabaseReference, (LPCTSTR)szTransformFile, 0, 0);	//Release the string	env->ReleaseByteArrayElements(transformFile, (signed char*)szTransformFile, 0);	return errorCode;}/* * Class:     org_jdesktop_jdic_packager_impl_WinMsiWrapper * Method:    UpdateResourceString * Signature: ([B[BI)I */JNIEXPORT jint JNICALL Java_org_jdesktop_jdic_packager_impl_WinMsiWrapper_updateResourceString(JNIEnv * env, jclass jc, jbyteArray appName, jbyteArray contentStr, jint resID){    //Construct the parameter    LPCTSTR szAppName = (LPCTSTR)env->GetByteArrayElements(appName, NULL);    LPCTSTR szContentStr = (LPCTSTR)env->GetByteArrayElements(contentStr, NULL);    HANDLE hUpdateApp;    //Get the handle to the application    hUpdateApp = BeginUpdateResource(szAppName, false);    if (hUpdateApp != NULL)    {        //Get the resource length        int nStrLen = strlen(szContentStr);        DWORD dwResSize = (nStrLen + 2) * sizeof(WCHAR);        //prepare the string resources block        LPVOID pRes = malloc(dwResSize);        if (pRes != NULL)        {            WCHAR* pResChar = (WCHAR*)pRes;            *pResChar++ = nStrLen;            for (int i = 0; i < nStrLen; i++)            {                *pResChar++ = szContentStr[i];            }            UINT nBlockID = (resID / 16) + 1;            if (UpdateResource(hUpdateApp,                                RT_STRING,                                MAKEINTRESOURCE(nBlockID),                                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),                                (LPVOID)pRes,                                dwResSize))            {                if (EndUpdateResource(hUpdateApp, false))                {                    //Release the string	                env->ReleaseByteArrayElements(appName, (signed char*)szAppName, 0);	                env->ReleaseByteArrayElements(contentStr, (signed char*)szContentStr, 0);	                free(pRes);                    return 0;                }            }            free(pRes);        }    }    //Release the string	env->ReleaseByteArrayElements(appName, (signed char*)szAppName, 0);	env->ReleaseByteArrayElements(contentStr, (signed char*)szContentStr, 0);        return -1;}/* * Class:     org_jdesktop_jdic_packager_impl_WinMsiWrapper * Method:    UpdateResourceData * Signature: ()I */JNIEXPORT jint JNICALL Java_org_jdesktop_jdic_packager_impl_WinMsiWrapper_updateResourceData(JNIEnv * env, jclass jc, jbyteArray appName, jbyteArray dataFileName, jint resID){    //Construct the parameter    LPCTSTR szAppName = (LPCTSTR)env->GetByteArrayElements(appName, NULL);    LPCTSTR szDataFileName = (LPCTSTR)env->GetByteArrayElements(dataFileName, NULL);        HANDLE hFile;    DWORD dwFileSize, dwBytesRead;    LPBYTE lpBuffer;    //Open the data file    hFile = CreateFile(szDataFileName,                       GENERIC_READ,                       0,                       NULL,                       OPEN_EXISTING,                       FILE_ATTRIBUTE_NORMAL,                       NULL);    if (INVALID_HANDLE_VALUE != hFile)    {        dwFileSize = GetFileSize(hFile, NULL);        lpBuffer = new BYTE[dwFileSize];        if (ReadFile(hFile, lpBuffer, dwFileSize, &dwBytesRead, NULL) != FALSE)        {            HANDLE hResource;            hResource = BeginUpdateResource(szAppName, false);            if (hResource != NULL)            {                if (UpdateResource(hResource,                                   RT_RCDATA,                                   MAKEINTRESOURCE(104),                                   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),                                   (LPVOID) lpBuffer,                                   dwFileSize) != FALSE)                 {                    EndUpdateResource(hResource, FALSE);                }            }        }        delete[] lpBuffer;        CloseHandle(hFile);        //Release the string	    env->ReleaseByteArrayElements(appName, (signed char*)szAppName, 0);	    env->ReleaseByteArrayElements(dataFileName, (signed char*)szDataFileName, 0);        return 0;    }    //Release the string	env->ReleaseByteArrayElements(appName, (signed char*)szAppName, 0);	env->ReleaseByteArrayElements(dataFileName, (signed char*)szDataFileName, 0);    return -1;}/* * Class:     org_jdesktop_jdic_packager_impl_WinMsiWrapper * Method:    genUUID * Signature: ()[B */JNIEXPORT jbyteArray JNICALL Java_org_jdesktop_jdic_packager_impl_WinMsiWrapper_genUUID  (JNIEnv * env, jclass jc){	jbyteArray result = NULL;	unsigned char UUIDBuffer[MAX_RECORD_STRING_LENGTH];	char UUIDString[MAX_RECORD_STRING_LENGTH];    UUID newUUID;	UuidCreate(&newUUID);	unsigned char * pStrUUID = UUIDBuffer;	if (UuidToString(&newUUID, (unsigned char **)&pStrUUID) != RPC_S_UUID_NO_ADDRESS)	{	    sprintf(UUIDString, "%s", pStrUUID);	    int bufCount = strlen(UUIDString);        result = env->NewByteArray(bufCount);  		if (result != NULL) 		{			env->SetByteArrayRegion(result, 0, bufCount, (jbyte *) UUIDString);		}        return result;	}	return NULL;}/* * Class:     org_jdesktop_jdic_packager_impl_WinMsiWrapper * Method:    MsiCreateRecord * Signature: (I)I */JNIEXPORT jint JNICALL Java_org_jdesktop_jdic_packager_impl_WinMsiWrapper_msiCreateRecord  (JNIEnv * env, jclass jc, jint numRecords){    int msiRecordHandle;    msiRecordHandle = MsiCreateRecord(numRecords);    if ( msiRecordHandle != NULL)     {        return msiRecordHandle;          }    else     {        return -1;    }}/* * Class:     org_jdesktop_jdic_packager_impl_WinMsiWrapper * Method:    MsiDatabaseImport * Signature: (I[B[B)I */JNIEXPORT jint JNICALL Java_org_jdesktop_jdic_packager_impl_WinMsiWrapper_msiDatabaseImport  (JNIEnv * env, jclass jc, jint hDatabase, jbyteArray folderPath, jbyteArray txtFileName){    //Construct the parameter    LPCTSTR szFolderPath = (LPCTSTR)env->GetByteArrayElements(folderPath, NULL);    LPCTSTR szFileName = (LPCTSTR)env->GetByteArrayElements(txtFileName, NULL);    int errorCode = MsiDatabaseImport(hDatabase, szFolderPath, szFileName);    //Release the string	env->ReleaseByteArrayElements(folderPath, (signed char*)szFolderPath, 0);	env->ReleaseByteArrayElements(txtFileName, (signed char*)szFileName, 0);	return errorCode;}/* * Class:     org_jdesktop_jdic_packager_impl_WinMsiWrapper * Method:    MsiDatabaseApplyTransform * Signature: (I[BI)I */JNIEXPORT jint JNICALL Java_org_jdesktop_jdic_packager_impl_WinMsiWrapper_msiDatabaseApplyTransform  (JNIEnv * env, jclass jc, jint hDatabase, jbyteArray tranformFile, jint iErrorConditions){    //Construct the parameter    LPCTSTR szTransformFile = (LPCTSTR)env->GetByteArrayElements(tranformFile, NULL);    int errorCode = MsiDatabaseApplyTransform(hDatabase, szTransformFile, iErrorConditions);    //Release the string	env->ReleaseByteArrayElements(tranformFile, (signed char*)szTransformFile, 0);    return errorCode;}#ifdef __cplusplus}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -