Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/first-steps/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ In this case we'll be using the manual way of getting references to methods, but
MonoObject* InstantiateClass(const char* namespaceName, const char* className)
{
// Get a reference to the class we want to instantiate
MonoClass* testingClass = GetClassInAssembly(s_AppAssembly, "", "CSharpTesting");
MonoClass* testingClass = GetClassInAssembly(s_AppAssembly, namespaceName, className);

// Allocate an instance of our class
MonoObject* classInstance = mono_object_new(s_AppDomain, testingClass);
Expand All @@ -39,6 +39,8 @@ MonoObject* InstantiateClass(const char* namespaceName, const char* className)

// Call the parameterless (default) constructor
mono_runtime_object_init(classInstance);

return classInstance;
}

void CallPrintFloatVarMethod(MonoObject* objectInstance)
Expand Down Expand Up @@ -147,4 +149,4 @@ In the second example we don't just declare a `void*`, but rather an *array* of

If you're wondering how Mono knows what the size of the data array that we pass is, it's simply because it expects the total size of that array to equal the size of *all* the parameters in the C# method, meaning if the array size doesn't match the parameter count you will end up with problems, and Mono *may* not tell you about it.

And that's the basics of how we can retrieve and invoke C# methods from C++! I will obviously go into more depth about parameter types and how we can convert between C++ types and C# types later on.
And that's the basics of how we can retrieve and invoke C# methods from C++! I will obviously go into more depth about parameter types and how we can convert between C++ types and C# types later on.