printf な ダイアログDBアプリ

  stdafx.h の変更



  
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
    no_namespace rename("EOF", "EndOfFile")

// Windows ヘッダー ファイル:
#include <windows.h>

// C ランタイム ヘッダー ファイル
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
  



  COM 初期化



  
// *********************************************************
// main
// *********************************************************
int main(int argc, char* argv[])
{
	printf("Hello World!\n");

	CoInitialize(NULL);

	DialogBox(
		NULL,
		(LPCTSTR)IDD_DIALOG1,
		::GetDesktopWindow(),
	(DLGPROC)PrintfDialog);

	CoUninitialize();

	return 0;
}
  



  Query サンプル

  
#include "stdafx.h"
#include "resource.h"

inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};

// 接続文字列
char *ConnectionString =
	"Provider=MSDASQL"
	";DSN=MySQL"
	";DATABASE=lightbox"
	";UID=root"
	";PWD="
	";";

// エラー処理用
ErrorPtr pErr = NULL;

void QuerySample( )
{
	printf("QuerySample\n");

	_ConnectionPtr pCn;
	_RecordsetPtr pRs;
	_bstr_t ConString;
	_bstr_t BBuff;
	_variant_t VBuff;

	try {
		// 接続インスタンス作成
		TESTHR(pCn.CreateInstance(__uuidof(Connection)));
		ConString.operator = ( ConnectionString );
		printf( "接続文字列は[%s]です\n", (LPTSTR)ConString );
		// 接続
		pCn->Open(ConString, "", "", adConnectUnspecified);

		// レコードセットインスタンス作成
		TESTHR(pRs.CreateInstance(__uuidof(Recordset)));

		// SQL
		VBuff.operator = ("select * from 商品分類マスタ");

		// レコードセット取得
		pRs->Open(
			VBuff,
			_variant_t((IDispatch *)pCn,true),
			adOpenKeyset,
			adLockOptimistic,
			adCmdText
		);

		// フィールドデータ取得
		while( !(pRs->EndOfFile) ) {

			VBuff = pRs->Fields->GetItem("商品分類")->Value;
			BBuff.operator = (VBuff);
			printf( "商品分類 = %s,", (LPTSTR)BBuff );

			VBuff = pRs->Fields->GetItem("作成日")->Value;
			BBuff.operator = (VBuff);
			printf( "作成日 = %s\n", (LPTSTR)BBuff );

			// 次のレコード
			pRs->MoveNext();
		}

		// 終了処理
		pRs->Close();
		pCn->Close();
	}
	catch ( _com_error &e ) {
		if( (pCn->Errors->Count) > 0) {
			printf("ProviderError\n");
			long i,nCount;
			nCount = pCn->Errors->Count;
			for( i = 0; i < nCount; i++ ) {
				pErr = pCn->Errors->GetItem(i);
				printf("\tError number: %x\n", pErr->Number );
				printf("\tDescription: %s\n", (LPTSTR)pErr->Description);
			}
		}

		_bstr_t bstrSource(e.Source());
		_bstr_t bstrDescription(e.Description());

		printf("ComError\n");
		printf("\tCode = %08lx\n", e.Error());
		printf("\tCode meaning = %s\n", e.ErrorMessage());
		printf("\tSource = %s\n", (LPTSTR)bstrSource);
		printf("\tDescription = %s\n", (LPTSTR)bstrDescription);
	}
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ