Kotlin: Unresolved reference: win32


hi :slight_smile: i dont understand this error. i using idea from jetbains. may you could help. thanks

import win32.*
fun main(args: Array) {
  println("Hello, World!")
  MessageBoxW(null, "hi!","ho", MB_YESNOCANCEL or MB_ICONQUESTION)

IntelliJ IDEA 2017.3.4 (Ultimate Edition)
Build #IU-173.4548.28, built on January 29, 2018
JRE: 1.8.0_152-release-1024-b11 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0


Which library are you trying to load win32 from? Did you add it to your dependencies? As far as I know there is no win32 package in java.

Also MessageBoxW sounds like you are trying to access c++ code from within Kotlin. Correct me if I’m wrong.


Later i downloadet this and tried to move it into “External Libraries” folder:
It could not be added. Sorry, I should have added this info earlier, I was distracted.

The source example i got from here:

I dont know if MessageBoxW is c++ code. If yes it will surprices me.


I am not really sure if Kotlin Native is supported by IntelliJ, try using CLion.


If I understand the native support correctly CLion is the official Editor for Kotlin Native. There is also a gradle plugin but CLion does not support gradle. So the state of Kotlin Native support is kind of strange right now.

But I think the problem @SL5 is having is that he is trying to use a Kotlin Native library in a Kotlin JVM build, which is not possible. I am 99% sure MessageBoxW is the wrapper for the unicode version of https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx

Looking at the win32 sample in the zip file, I am now 100% sure. In there, there is a win32.def file importing the headers to windows.h which contains MessageBoxW function.

As to fixing this, either try using CLion and do a Kotlin Native build. You will also specify the win32.def as seen in the example or use the java libraries to create the message box: https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html