OleAutoObject

Deutschsprachiges X#-Forum – German language forum

Moderator: wriedmann

lagraf
Posts: 450
Joined: Thu Jan 18, 2018 9:03 am
Location: A

OleAutoObject

Post by lagraf »

Ich habe mehrer VO Apps die OleAutoObject verwenden.
Nach dem Transport beim Import in die XIDE wird gemeldet dass die Lib OLE fehlt, daher funktionieren alle OleAutoObject Methoden nicht, XSharp.VO ist referenziert.

Trage ich USING OleAutoObject ein, bekomme ich den Fehler XS0246
Trage ich USING OleAutoObject NICHT ein, bekomme ich den Fehler XS0012 bei allen Methoden

Was muss ich tun, damit ich OleAutoObject in X# verwenden kann?

Danke für Infos, Franz
User avatar
Chris
Posts: 4936
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: OleAutoObject

Post by Chris »

Hi Franz,

It depends on what you are using OLE for. Please read first the documentation at https://www.xsharp.eu/help/example-4-ol ... ation.html and https://www.xsharp.eu/help/example-4-th ... t-exa.html and if you need further advice, please ask.

The online samples show how to create interop assemblies in VS, you can do that and then use the dlls also in XIDE (add references to the dlls). Or you can use in XIDE Tools->Create Interop Assemblies
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
lagraf
Posts: 450
Joined: Thu Jan 18, 2018 9:03 am
Location: A

Re: OleAutoObject

Post by lagraf »

Hi Chris,
in VO app I'm using a com enabled DLL called sendmail.dll which I got from Wolfgang. The interface for this DLL gives all the OLE errors. Maybe Wolfgang has a X# Version of this sendmail.dll, then the interface would not be necessary?

Some other errors are from DIBSetProgressControl which I use for a progress dialog:

Code: Select all

oDlg := dlgProgress{ }
oDlg:SetMarquee(TRUE, 1)
oDlg:Show(SHOWCENTERED)
ApplicationExec( EXECWHILEEVENT )
DIBSetProgressControl( oDlg:oDCProgressBar:Handle() )	// => XS0103
ApplicationExec( EXECWHILEEVENT )
Franz
User avatar
wriedmann
Posts: 3765
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: OleAutoObject

Post by wriedmann »

Hi Franz,
the SendMail.dll IS a X# DLL.
You can use it directly in the references, no need to use COM anymore.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
lagraf
Posts: 450
Joined: Thu Jan 18, 2018 9:03 am
Location: A

Re: OleAutoObject

Post by lagraf »

Ok, ich werfe die OLE Teile dann mal raus und rufe die Methoden direkt auf.
Dann brauche ich das Interface ISmtpSender nicht sondern benutze die Klasse SmtpSender direkt?
Franz
User avatar
wriedmann
Posts: 3765
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: OleAutoObject

Post by wriedmann »

Hallo Franz,
das gilt für alle meine X# COM DLLs - sehr wichtig für uns bei der Migration nach X#.
Und ja genau: SmtpSender ist direkt zu verwenden.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
lagraf
Posts: 450
Joined: Thu Jan 18, 2018 9:03 am
Location: A

Re: OleAutoObject

Post by lagraf »

Hallo Wolfgang,
ich habs inzwischen geändert, kanns aber nicht testen, da ich noch ein paar andere Fehler bekomme, die ich nicht korrigieren kann:

1) Für einen ProgressBar verwende ich DIBSetProgressControl( oDlg:oDCProgressBar:Handle() ) und bekomme den Fehler
error XS0103: The name 'DIBSetProgressControl' does not exist in the current context

2) In VO hatte ich zur Ermittlung der laufenden Prozesse
EnumWindows(@OGS_EnumAddItemToArray(),LONGINT(_CAST,aWindows))
Der Transporter hat mir daraus ein Delegate gemacht

Code: Select all

STATIC LOCAL oOGS_EnumAddItemToArrayDelegate := OGS_EnumAddItemToArray AS OGS_EnumAddItemToArray_Delegate
EnumWindows(System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(oOGS_EnumAddItemToArrayDelegate),LONGINT(_CAST,aWindows))
Allerdings versteht der Compiler das LONGINT(_CAST,aWindows) nicht mehr und gibt mir den Fehler
error XS0030: Cannot convert type 'array' to 'int'

3) Ich habe eine Klasse Mailing und eine zweite Klasse Etikette, die von Mailing abgeleitet wird:

Code: Select all

CLASS Mailing
CONSTRUCTOR(oOwner AS window, cName AS STRING)
...
CLASS Etikette INHERIT Mailing
CONSTRUCTOR(oOwner AS window, cName AS STRING)
...
oRpReport := Mailing{SELF,cRpName}
oRpReport := Etikette{SELF,cRpName}
Da bekomme ich den Fehler
error XS7036: There is no argument given that corresponds to the required formal parameter 'oOwner' of 'Mailing.Mailing(VO.Window, string)'

Grundsätzlich könnte ich den Constructor von Etikette auch weglassen, da er identisch ist mit dem von Mailing. Aber das mag der Compiler auch nicht und gibt zusätzlich zu dem XS7036 aus:
error XS1729: 'Etikette' does not contain a constructor that takes 2 arguments

Kannst du mir bei den Fehlern auf die Sprünge helfen?

LG Franz
lagraf
Posts: 450
Joined: Thu Jan 18, 2018 9:03 am
Location: A

Re: OleAutoObject

Post by lagraf »

Ich habe ausserdem noch ein paar VO Apps, die einen OLEAutoObject XML Parser verwenden:
CLASS MyIXMLDOMDocument INHERIT OLEAutoObject

Wie bekomme ich den in X# zum Laufen?
Franz
User avatar
Chris
Posts: 4936
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: OleAutoObject

Post by Chris »

Hi Franz,

1. In your VO app, where is DIBSetProgressControl() defined and how?

2. The proper way to do this (pass a managed (.Net) object to an umanaged (windows)) function is to use the GCHandle class (in the System.Runtime.InteropServices namespace) to allocate a managed handle to it with GCHandle.Alloc() and pass it to the function, but in most cases most probably it's simpler to not pass anything as a parameter (just pass an empty pointer) and use a class var instead. Can you please show all the relevant code, where aWindows is defined and how, and where it is used and how?

3. What is "SELF" in this context? It needs to represent a (VO) window object.

About the XML parser, did you read the links I posted earlier? They should give the information on how to do this in X#, but please ask if anything is not clear.

Btw, in order to test your progress in converting your app so far, you can just ignore the parts that give compiler errors. Just comment those pieces of code out, compile the app and test what you have so far if it runs properly. After you make sure all that is properly converted works well, you can then take care of the remaining parts.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
lagraf
Posts: 450
Joined: Thu Jan 18, 2018 9:03 am
Location: A

Re: OleAutoObject

Post by lagraf »

Hi Chris,
1) In VO I use DIBSetProgressControl() to show a progress bar:

Code: Select all

oDlg := dlgProgress{ }	// progressbar dialog
oDlg:SetMarquee(TRUE, 1)
oDlg:Show(SHOWCENTERED)
ApplicationExec( EXECWHILEEVENT )
DIBSetProgressControl( oDlg:oDCProgressBar:Handle() )
ApplicationExec( EXECWHILEEVENT )
// Sending email with attachment ...
DIBSetProgressControl( NULL_PTR )
2) Get the open windows (I think I found this functions many years ago somethere in a forum), this is what transporter made:

Code: Select all

DELEGATE OGS_EnumAddItemToArray_delegate(ptrWnd AS PTR , aWindows AS ARRAY) AS WORD 
STATIC FUNCTION OGS_EnumAddItemToArray(ptrWnd AS PTR , aWindows AS ARRAY) AS WORD CALLBACK

	IF aWindows[1] <= aWindows[2]				// number of elements <= max elements?
		aWindows[++aWindows[3]] := ptrWnd		// save handle
		aWindows[1] := ++aWindows[1]			// raise number of elements
	ELSE									// array zu small?
		aWindows[1] := -1					// return error
		RETURN 0
	ENDIF
		
	RETURN 1

FUNCTION OGS_EnumWindows() AS ARRAY PASCAL
	LOCAL aWindows AS ARRAY
	LOCAL loFaktor	AS DWORD
	
	aWindows := ArrayCreate(1024)
	aWindows[1] := 0				// Number of elements
	loFaktor := 1
	
	DO WHILE aWindows[1] = 0
		
		// max number of elements
		aWindows[2] := 1024*loFaktor
		// starting element-1
		aWindows[3] := 3
//#warning Callback function modified to use a DELEGATE by xPorter. Please review.
//EnumWindows(@OGS_EnumAddItemToArray(),LONGINT(_CAST,aWindows))
STATIC LOCAL oOGS_EnumAddItemToArrayDelegate := OGS_EnumAddItemToArray AS OGS_EnumAddItemToArray_Delegate
EnumWindows(System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(oOGS_EnumAddItemToArrayDelegate),LONGINT(_CAST,aWindows))
		IF aWindows[1] = -1
			
			aWindows := ArrayCreate(1024*(++loFaktor))	// too less elements
			aWindows[1] := 0
			aWindows[2] := 1024*loFaktor
			aWindows[3] := 3

		ELSE
			
			EXIT
		
		ENDIF
		
	ENDDO

	loFaktor := aWindows[1]
	aWindows := ADel(aWindows,1)                 		// delete element 1,2,3
	aWindows := ADel(aWindows,1)
	aWindows := ADel(aWindows,1)
	aWindows := ASize(aWindows,loFaktor)			// running windows

	RETURN aWindows
3) SELF is a DialogWindow

XML Parser:
It's on my schedule next week, at this week I'm very busy.

Testing progress:
If it concerns a small part of the app I do so.
But if the app would not run if I comment it out cause it's a necessary part, then it's not possible.

Thanks for answer
Franz
Post Reply