Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Create a Port_Type structure
Message
De
14/03/2005 16:16:37
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
How to Create a Port_Type structure
Versions des environnements
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP2
Network:
Windows NT
Database:
Visual FoxPro
Divers
Thread ID:
00995713
Message ID:
00995713
Vues:
171
Hello everybody.

in my quest to automaticly add a printer-port in windows 98 and up (thread #995563), i am trying the AddPortEx() API. for this i need to pass 1 of 2 structures to the function: "_PORT_INFO_1" or "_PORT_INFO_2". the following test code should add a valid network printer port. but i am not sure how to exactly/correctly create those 2 structures.
CLEAR

nResult = 0

DECLARE INTEGER GetLastError IN kernel32
DECLARE INTEGER FindWindow ;
	IN user32.DLL ;
	STRING @, ;
	STRING @
DECLARE INTEGER AddPort IN winspool.drv;
	STRING pName, ;
	INTEGER HWND, ;
	STRING pMonitorName
DECLARE INTEGER AddPortEx IN winspool.drv;
	STRING pName, ;
	INTEGER LEVEL, ;
	STRING pPorts, ;
	STRING pMonitorName
* ***	BOOL (WINAPI *pfnAddPortEx)(
* ***	    LPWSTR pName,
* ***	    DWORD Level,
* ***	    LPBYTE lpBuffer,
* ***	    LPWSTR lpMonitorName
* ***	   );


IF TYPE("_SCREEN.Hwnd") <> "N"
	_SCREEN.ADDPROPERTY("Hwnd", FindWindow(0, _SCREEN.CAPTION))
ENDIF

* ***	typedef struct _PORT_INFO_1 { // pi1 
* ***	    LPTSTR pName; 
* ***	} PORT_INFO_1; 

* ***	typedef struct _PORT_INFO_2 { // pi2 
* ***	    LPSTR pPortName; 
* ***	    LPSTR pMonitorName 
* ***	    LPSTR pDescription; 
* ***	    DWORD fPortType; 
* ***	    DWORD Reserved; 
* ***	} PORT_INFO_2; 

* *** this works (manually type the portname into the dialoge)
*nResult = AddPort(.NULL., _SCREEN.HWND, "Local Port")

_PORT_INFO_1 = ;
	"\\KICUSTSVC13\CUST1" + chr(0)

#define PORT_TYPE_WRITE         0x0001
#define PORT_TYPE_READ          0x0002
#define PORT_TYPE_REDIRECTED    0x0004
#define PORT_TYPE_NET_ATTACHED  0x0008

_PORT_INFO_2 = ;
	"\\KICUSTSVC13\CUST1" + chr(0) + ;
	.null. + ;
	"Gunni AddPort Test" + chr(0) + ;
	trans(PORT_TYPE_READ+PORT_TYPE_WRITE+PORT_TYPE_NET_ATTACHED) + chr(0) + ;
	.null.

* *** 
nResult = AddPortEx(;
	.null., ;
	2, ;
	_PORT_INFO_2, ;
	.null.)

?nResult
IF nResult = 0
	ErrCode	= GetLastError()
	ErrMsg	= oToolBox.oGlobalStr.ApiErrorText(m.ErrCode)
	MESSAGEBOX(TRANS(m.ErrCode) +", "+ m.ErrMsg)
ENDIF
thanks for all your help!
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform