Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, degenerate_762, ozgur), 1,311 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
COM Interop Problems / Bugs #464158
01/25/17 18:15
01/25/17 18:15
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
I wanted to try out COM interop and unfortunately ran into some problems/bugs when including the needed headers. This is with my Zorro S 1.50.6.

Code:
#include <litec.h>
#include <com.h>

function run()
{
	
}



This gives:
Code:
Error in 'line 4: 
'function' undeclared identifier
< function run()
 >.



Since when uses any headers one has to manually include default.c, so I did that too:

Code:
#include <default.c>
#include <litec.h>
#include <com.h>

function run()
{
	
}



This unfortunately gives:
Code:
Error in 'windows.h' line 6610: 
syntax error
< VOID WINAPI FillMemory(long Destination,DWORD Length,char Fill);
 >.



I tried changing function run() to int run(). Then I also got a strange error message:

Code:
#include <litec.h>
#include <com.h>

int run()
{
	
}



Gives:
Code:
Test8 compiling.......
Error 061: Compiled with different version!



How to fix this?

Last edited by trenki2; 01/25/17 18:38.
Re: COM Interop Problems / Bugs [Re: trenki2] #464161
01/25/17 19:41
01/25/17 19:41
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
I was able to make things work by changing something in windows.h.
I changed the parameter name in the FillMemory from "Fill" to "fill" and it worked:

Code:
VOID WINAPI FillMemory(long Destination,DWORD Length,char fill);



With the above line this compiles now:

Code:
#include <default.c>
#include <litec.h>
#include <com.h>

function run()
{
	
}


Re: COM Interop Problems / Bugs [Re: trenki2] #464162
01/25/17 20:14
01/25/17 20:14
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
I still have problems making the COM Interop work. I have a C# COM DLL which is registered in the system. I can do CoInitialize and also CoCreateInstance seems to work but afterwards the functions that I call seem to not work or return the wrong results or even crash.

The complete project is here: http://www.filedropper.com/zorrotoolbox

Its quite small. One just has to compile it in Visual Studio and place the Zorro files in the include and strategy folder respectively. It would be nice to get a fully working minimal example together so we could put it in the Zorro documentation to help others.

The documentations also describes two possible ways to call the functions. Either via C++ style, or via C-style.
When i try the C-style I unfortunately get a compiler error:

Code:
#include <default.c>
#include <litec.h>
#include <com.h>
#include <ZorroToolbox.h>

int WINAPI main()
{
	HRESULT hr = CoInitialize(NULL);
	if (hr != S_OK)
	{
		printf("CoInitialize Failed: %xnn", hr);
		quit();
	} 
	else
	{
		printf("CoInitialize succeededn");	
	}
	
	IDoubleList *list = DoubleList_New();
	if (!list)
		printf("Failed to allocate objectn");
	
	// Call via C-syle call -> Compiler error
        // @temp_00582(): wrong number of parameters
        // < 	hr = list->lpVtbl->ShowMessageBox(list);	
	hr = list->lpVtbl->ShowMessageBox(list);
	
	list->Release();
	
	CoUninitialize();
}



The code looks like this:

Code:
#include <default.c>
#include <litec.h>
#include <com.h>
#include <ZorroToolbox.h>

int WINAPI main()
{
	HRESULT hr = CoInitialize(NULL);
	if (hr != S_OK)
	{
		printf("CoInitialize Failed: %xnn", hr);
		quit();
	} 
	else
	{
		printf("CoInitialize succeededn");	
	}
	
	IDoubleList *list = DoubleList_New();
	if (!list)
		printf("Failed to allocate objectn");
	
	hr = list->ShowMessageBox();
	if (hr != S_OK)
		printf("ShowMessageBox failedn");
		
	hr = list->Add(1.0);
	if (hr != S_OK)
		printf("Add failedn");
	list->Add(5.0);
	list->Add(3.0);
	list->Add(2.0);
	list->Sort();
	
	long count;
	list->Count(&count);
	printf("Count: %in", count);
	
	double value;
	list->GetItem(0, &value);
	printf("Item: %fn", value);
	
	long i;
	for (i = 0; i < count; ++i)
	{
		double value;
		list->GetItem(i, &value);
		printf("%fn", value);
	}
	
	list->Release();
	CoUninitialize();
}



and this is the ZorroToolbox.h file:

Code:
typedef struct _IDoubleListVtbl
{
	HRESULT __stdcall QueryInterface(void* This, IID *riid, void** ppvObject);
	DWORD   __stdcall AddRef(void* This);
	DWORD   __stdcall Release(void* This);

	HRESULT __stdcall Add(/*[in]*/ void *This, /*[in]*/ double value);
	HRESULT __stdcall Insert(/*[in]*/ void *This, /*[in]*/ long index, /*[in]*/ double value);
	HRESULT __stdcall Remove(/*[in]*/ void *This, /*[in]*/ double value);
	HRESULT __stdcall RemoveAt(/*[in]*/ void *This, /*[in]*/ long index);
	HRESULT __stdcall RemoveRange(/*[in]*/ void *This, /*[in]*/ long index, /*[in]*/ long count);
	HRESULT __stdcall Reverse(/*[in]*/ void *This);
	HRESULT __stdcall ReverseRange(/*[in]*/ void *This, /*[in]*/ long index, /*[in]*/ long count);
	HRESULT __stdcall SetItem(/*[in]*/ void *This, /*[in]*/ long index, /*[in]*/ double value);
	HRESULT __stdcall GetItem(/*[in]*/ void *This, /*[in]*/ long index, /*[out,retval]*/ double * pRetVal);
	HRESULT __stdcall Clear(/*[in]*/ void *This);
	HRESULT __stdcall Count(/*[in]*/ void *This, /*[out,retval]*/ long * pRetVal);
	HRESULT __stdcall Sort(/*[in]*/ void *This);

	HRESULT __stdcall ShowMessageBox(/*[in]*/ void *This);
} IDoubleListVtbl;

typedef interface IDoubleList { IDoubleListVtbl *lpVtbl; } IDoubleList;

IDoubleList* DoubleList_New()
{
	IDoubleList *pList = NULL;

	GUID clsid;
	IID iid;

	IIDFromStr("{AC9831A9-2433-409E-967F-4B74127F3B12}", &clsid);
	IIDFromStr("{EF4A8708-0FBF-4959-B8B9-FD1F1846B77A}", &iid);

	HRESULT hr = CoCreateInstance(&clsid, NULL, CLSCTX_ALL, &iid, &pList);
	return pList;
}



And this the C# Code:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ZorroToolbox
{
    [ComVisible(true), Guid("EF4A8708-0FBF-4959-B8B9-FD1F1846B77A")]
    public interface IDoubleList
    {
        void Add(double value);
        void Insert(int index, double value);
        void Remove(double value);
        void RemoveAt(int index);
        void RemoveRange(int index, int count);
        void Reverse();
        void ReverseRange(int index, int count);
        void SetItem(int index, double value);
        double GetItem(int index);
        void Clear();
        int Count();
        void Sort();

        void ShowMessageBox();
    }

    [ClassInterface(ClassInterfaceType.None)]
    [ComVisible(true), Guid("AC9831A9-2433-409E-967F-4B74127F3B12")]
    public class DoubleList : IDoubleList
    {
        private List<double> data = new List<double>();

        public void Add(double value)
        {
            data.Add(value);
        }

        public void Clear()
        {
            data.Clear();
        }

        public int Count()
        {
            return data.Count;
        }

        public double GetItem(int index)
        {
            return data[index];
        }

        public void Insert(int index, double value)
        {
            data.Insert(index, value);
        }

        public void Remove(double value)
        {
            data.Remove(value);
        }

        public void RemoveAt(int index)
        {
            data.RemoveAt(index);
        }

        public void RemoveRange(int index, int count)
        {
            data.RemoveRange(index, count);
        }

        public void Reverse()
        {
            data.Reverse();
        }

        public void ReverseRange(int index, int count)
        {
            data.Reverse(index, count);
        }

        public void SetItem(int index, double value)
        {
            data[index] = value;
        }

        public void Sort()
        {
            data.Sort();
        }

        public void ShowMessageBox()
        {
            MessageBox.Show("MessageBox Text");
        }
    }
}



Zorro sais the script crashes. Even the ShowMessageBox line does not work. No message box is shown.

Last edited by trenki2; 01/25/17 21:21.

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1