2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by gerard4143
0

Do you mean, how does a C object file that has been linked into a C++ project, retrieve/accept the GUID of an object?

Edited by gerard4143: n/a

0

Do you mean, how does a C object file that has been linked into a C++ project, retrieve/accept the GUID of an object?

Say I'm writing a program in C and need to use a function like this:
void SomeFunction(IID* refiid);

In C++ I would do this:
SomeFunction(__uuidof(&SomeObject));

How would I call that function in C?

0

I know how to solve this in Linux using GCC but the solution is not portable...That said you should be able to use the concept which is....wrapping the C++ functionality in a C calling sequence, see below

testit.cpp

#include <iostream>

extern "C" void PrintStr(char *str);

void PrintStr(char *str)
{
	std::cout << "From Cpp Object file->" << str << std::endl;
}

testit.h

void PrintStr(char *str);

test.c

#include "testit.h"

int main()
{
	char ch[] = "From the C program";

	PrintStr(ch);
	return 0;
}

And my compile lines

g++ -Wall -ansi -pedantic -c testit.cpp
gcc testit.o test.c -o test -Wall -ansi -pedantic -lstdc++

Note the inclusion of the standard C++ library with the -lstdc++ switch..Hope this helps.

Output:

From Cpp Object file->From the C program

Edited by gerard4143: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.