장성호님이 알려주신 코드로 수정하니 코드도 쉽고 문제도 해결했습니다.
감사합니다.
한가지 더 문의 하고 싶은것은
제가 버전 5.0 Help - 색인 메뉴얼에 찾아 봐도 아래
GetProcAddressf , GetDefaultPrinterA 함수를 찾아 볼수 없어서
C++Builder Help 버전이나 , 사이트좀 알려주셨으면 합니다.
장성호 님이 쓰신 글 :
: RptGetDefault = (_PRINT_GETDEF_)::GetProcAddress(m_hPrintHandle, TEXT("GetDefaultPrinterA"));
:
: 이 부분에서 RptGetDefault 여기에 NULL인것 같은데요..
: hPrintHandle 에 NULL이어서 그런것같구요
:
: C++Builder에서는
: GetProcAddressf로 GetDefaultPrinterA 함수를 찾을 필요 없이 바로 사용하면 됩니다.
:
: void __fastcall TForm2::Panel1Click(TObject *Sender)
: {
: String sPrinterName;
: DWORD dwBufSize=256;
: char buf[256];
: GetDefaultPrinterA(buf,&dwBufSize);
: sPrinterName=buf;
: ShowMessage(sPrinterName);
: }
: //---------------------------------------------------------------------------
:
:
: 참조하세요
:
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_qna&no=13963
:
: 그럼..
:
:
: 초보자 님이 쓰신 글 :
: : //디폴트 프린트 이름을 가져오는 프로그램을 코딩중에.. 에러가 나서요..
: :
: :
: : //TEST ----------2 까지는 나오는데
: : //TEST----------3에서 프로그램이 종료됩니다.
: : 고수님 코드중에 무엇이 잘못됬나여
: :
: : [test.h]
: : HMODULE m_hPrintHandle;
: :
: : [test.cpp]
: :
: : typedef BOOL (WINAPI * _PRINT_SETDEF_)(LPCSTR);
: : typedef BOOL (WINAPI * _PRINT_GETDEF_)(LPSTR, LPDWORD);
: :
: : ....
: :
: : bool __fastcall TFormSetup::CheckExternalIsDefault()
: : {
: :
: : _PRINT_GETDEF_ RptGetDefault;
: : bool bResult;
: : if(m_hPrintHandle != NULL)
: : {
: : RptGetDefault = (_PRINT_GETDEF_)::GetProcAddress(m_hPrintHandle, TEXT("GetDefaultPrinterA"));
: : }
: :
: : DWORD dwSize = 0;
: : RptGetDefault(NULL, &dwSize);
: : TCHAR* pszBuff = new TCHAR[dwSize];
: : memset(pszBuff, NULL, sizeof(TCHAR)*dwSize);
: :
: : ShowMessage("TEST___________________________________________________2");
: : RptGetDefault(pszBuff, &dwSize);
: : ShowMessage("TEST___________________________________________________3");
: :
: : //ShowMessage(pszBuff);
: : if(strstr(pszBuff, "STP-103") != NULL){
: : //bResult = false;
: : bResult = 0;
: : }
: : else{
: : //bResult = true;
: : bResult = 1;
: : }
: :
: : delete [] pszBuff;
: : return bResult;
: : }