COM 経由の実行

  「C から ADO」 を参考にして下さい



basp21.tlb を #import して、スマートポインタを利用します

  
#import <basp21.tlb> no_namespace
#include <windows.h>
#include <ole2.h>
#include <stdio.h>
#include <oleauto.h>
#include <conio.h>

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

  
void MySendMail3( HWND hWnd );
// バージョン情報ボックス用メッセージ ハンドラ
LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message ) {
		case WM_INITDIALOG:
			SetFocus( GetDlgItem( hDlg, IDC_TO ) );	
			return FALSE;

		case WM_COMMAND:
			if( LOWORD(wParam) == IDOK ) {
				if ( MessageBox(
						hDlg,
						"メールを送信しますか?",
						"確認",
						MB_OKCANCEL
						) == IDOK ) {
					MySendMail3( hDlg );
				}
				return TRUE;
			}
			if( LOWORD(wParam) == IDCANCEL ) {
				EndDialog( hDlg, LOWORD(wParam) );
				return TRUE;
			}
			break;
	}
	return FALSE;
}

IBasp21Ptr pBasp;
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
void MySendMail3( HWND hWnd )
{

	char *pszSmtpServer = "localhost";
	char szTo[80];
	char szFrom[80];
	char szSubject[80];
	char szBody[4096];
	char szErrorMessage[80];
	szErrorMessage[0] = 0x00;

	GetDlgItemText( hWnd, IDC_TO, szTo, 80 );
	GetDlgItemText( hWnd, IDC_FROM, szFrom, 80 );
	GetDlgItemText( hWnd, IDC_SUBJECT, szSubject, 80 );
	GetDlgItemText( hWnd, IDC_BODY, szBody, 4096 );

	CoInitialize(NULL);
	pBasp	= NULL;
	try {
		TESTHR(pBasp.CreateInstance(__uuidof(Basp21)));

		_bstr_t SmtpServer(pszSmtpServer);
		_bstr_t To(szTo);
		_bstr_t From(szFrom);
		_bstr_t Subject(szSubject);
		_bstr_t Body(szBody);
		_bstr_t File("");
		_bstr_t Ret("");

		Ret.operator = (pBasp->SendMail(SmtpServer,To,From,Subject,Body,File));
		if ( Ret.operator != ("") ) {
			MessageBox( hWnd, (LPSTR)Ret, "エラーメッセージ", MB_OK );
		}

		pBasp.Release();
		pBasp = NULL;
	}
	catch (_com_error &e)
	{
		MessageBox( hWnd, e.ErrorMessage(), "COM エラーメッセージ", MB_OK );
	}

	CoUninitialize();

}
  










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





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

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ