2017-01-24 5 views
0

Powerbuilder 11 버전에서 고유 한 파일 이름을 가져 오는 방법을 코드를 찾고 있습니다. 나는이 기능을 사용하고있다. 나는 다음과 같은 코드를 사용하지만,이 작품Powerbuilder - 고유 한 파일 이름을 얻으려면

FUNCTION integer GetTempFileName (ref string tempdir, ref string prefix, integer seed, ref string tempfile) LIBRARY "kernel32" alias for "GetTempFileNameW" 

string ls_prefixe = "app" 
integer li_seed = 0 
string ls_filename 
ls_filename = space(256) 

li_rc = GetTempFileName(ls_tempdir, ls_prefixe, li_seed, ls_filename) 
IF li_rc = 0 THEN 
    MessageBox("Oups", "Error") 
ELSE 
    MessageBox("Unique filename", ls_filename) 
END IF 
+0

누락 된'int li_rc'와'string ls_tempdir'을 추가하는 것만으로 코드가 내 PB11에서 작동합니다. "작동하지 않는"것은 무엇입니까? 오류 메시지, 구문 오류? – Seki

답변

0

작동하지 오전 :

글로벌 외부 기능 :

FUNCTION integer GetTempFileName (ref string tempdir, ref string prefix, integer seed, ref string tempfile) LIBRARY "kernel32" alias for "GetTempFileNameA;ANSI" 

코드 :

integer li_rc 
string ls_tempdir = "c:\temp\" 
string ls_prefixe = "app" 
integer li_seed = 0 
string ls_filename 

ls_filename = space(256) 

li_rc = GetTempFileName(ls_tempdir, ls_prefixe, li_seed, ls_filename) 
IF li_rc = 0 THEN 
    MessageBox("Oups", "Error") 
ELSE 
    MessageBox("Unique filename", ls_filename) 
END IF 
+0

'__; ANSI;'함수를 사용하면 오래된 un-unicode dll 함수를 호출 할 때나 오래된 10 이전 레거시 코드를 재사용 할 때 호환성 문제를 위해 별명을 예약해야합니다. PB는 내부적으로 10.0 버전부터'wide_char' 문자열 타입을 사용하고'__W' 윈도우 API 함수를 사용할 수 있습니다. ansi 변종을 사용하면 호출 전후에 문자열을'char'와'wchar_t' 형식으로 변환하여 호출에 과부하를 추가합니다. – Seki

+0

글쎄, 문제가 없다. 다음과 같이 전역 외부 함수를 변경하면된다. FUNCTION integer GetTempFileName (ref 문자열 tempdir, ref 문자열 접두어, 정수 시드, ref 문자열 tempfile) "GetTempFileNameW"에 대한 "kernel32"별칭 –

0

이 왜 할 파워 빌더를 사용 이건 Windows API가 아니겠습니까? Randomize 메서드를 사용하면 임의의 값을 쉽게 생성 할 수 있습니다. 출력은 정수이므로 여러 값을 생성하고 함께 연결할 수 있습니다.

예 :

String(Randomize(0)) + String(Randomize(0)) 

는 그런 다음 파일 이름으로 그것을 사용한다.

+0

이기 때문에 시스템이 보증 된 고유 한 파일 이름을 얻을 수있는 시설을 제공 할 수있을 때 브리 콜라주 (bricolage)? 어떤 이유로 첫 번째 파일 이름이 고유하지 않으면 고유 한 파일 이름을 가져올 때까지 API가 시드 번호를 늘립니다. – Seki

+0

나는 내 파일명으로 무작위 (0)를 사용하려고 시도했지만 난수는 나오지 않는다. 그러나 주어진 스크립트를 사용하면 고유 번호가 생성됩니다. – androidpol